Using the Hibernate property in a persistence.xml should result in the hibernate.ejb.use_class_enhancer application entity classes being enhanced by Hibernate. But this only works before the classes are loaded.
The same problem also has been reported by community users trying to use similar features with Versant/OpenJPA (EclipseLink will probably have the same issue).
Note that there was IRC discussion about the other ways to address this on #jboss-as7 (I'll attach a transcript later).
One possible solution:
- Only if classes are being enhanced or could be enhanced, would the other below steps be taken.
- When deploying the deployment persistence unit definitions, create a new application level classloader (similar to temp classloader).
- PersistenceUnitInfo.getClassLoader() will return the new classloader.
- Each entity manager invocation will set the TCCL to the PersistenceUnitInfo.getClassLoader().