-
1. Hibernate entity scanning with JBoss6 and Seam
genman Mar 21, 2011 5:34 PM (in response to grodd)Seam should probably use the JBoss one.
I'm guessing some sort of Seam example out there (maybe for JBoss 5?) would be a good way to start looking for how to configure this.
-
2. Hibernate entity scanning with JBoss6 and Seam
grodd Mar 24, 2011 2:21 PM (in response to genman)Thanks for the response Elias.
Based on your suggestion, I started looking into using the EntityManager created by JBoss. As it turns out, due to some recent changes to our project, the hibernate entity manager wasn't even being created by JBoss anymore. Based on the changes that were made, and the things they fixed, we figured it best to just let Seam handle the entity manager. So I kept digging and I managed to find a solution that seems to work well for us which I'll detail out now just incase someone is in the same situation.
The root of the problem was that when seam initilized the EntityMangerFactory, the scans for the classes annotated by @Entity was performed by org.hibernate.ejb.packaging.NativeScanner, which doesn't work under JBoss. What needed to run was org.jboss.scanning.hibernate.ScannerImpl which had support for VFS.
In persistence.xml, there is a property to set the resouce scanner hibernate.ejb.resource_scanner that can be used to specify the scanner used to find the entity classes. However it's not a simple matter of just setting it to ScannerImpl because the constuctor of ScannerImpl requires a org.jboss.deployers.structure.spi.DeploymentUnit. So one would have to create their own implementation of org.hibernate.ejb.packaging.Scanner, and in it get the current deployment unit and create a delegate that is ScannerImpl. To get the DeplotmentUnit my code looks something like this...
public JBossScannerImpl() {
ClassLoader cl = this.getClass().getClassLoader();
Module module = ClassLoading.getModuleForClassLoader(cl);
if (module instanceof AbstractDeploymentClassLoaderPolicyModule) {
AbstractDeploymentClassLoaderPolicyModule deploymentModule =
(AbstractDeploymentClassLoaderPolicyModule) module;
DeploymentUnit unit = deploymentModule.getDeploymentUnit();
_delegate = new ScannerImpl(unit);
}
}
Then, to fill out the methods required by implementing Scanner one can delegate the responsibility off to ScannerImpl. Finally all that has to be done is to refer to the new scanner implementation in persistence.xml
<persistence-unit name="SomePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.ejb.resource_scanner" value="your.scanner.Implemtation" />
</properties>
</persistence-unit>
And that shoud do the trick, I don't know if this is the best solution, and I think that if you have access to the EntityManager created by JBoss, that would be the way to go. But this seems to work for us.
-
3. Hibernate entity scanning with JBoss6 and Seam
ofd Mar 29, 2011 12:17 PM (in response to grodd)Thx, that post really saved my day .
I finally got rid of the damn "java.lang.IllegalArgumentException: Named query not found:" when migrating our ear from jboss4 to jboss6!
-
4. Hibernate entity scanning with JBoss6 and Seam
alesj Mar 29, 2011 1:58 PM (in response to grodd)Who creates EntityManagerFactory in this case?
Seam? But doesn't use JBossAS EMF creation?
JBossAS' EMF should already use ScannerImpl.
If not, then there is some bug in MC Scanning lib.
And that shoud do the trick, I don't know if this is the best solution
What about if instead of creating new ScannerImpl,
you look into DeploymentUnit if the Scanner attachment is already there?
e.g. _delegate = unit.getAttachment(Scanner.class);