-
1. Re: Persistence unit issues when migrating to JBOSS 5.1.0
dbobes Jan 7, 2010 4:46 PM (in response to dbobes)I found a way to specify which jars should be scanned for hibernate annotations. In persistence.xml:
<persistence-unit name="myapp"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/jdbc/myapp</jta-data-source> <jar-file>myseammodule.jar</jar-file> <properties> ... </persistence-unit>
Now the container scans the myseammodule.jar for hibernate classes and everything works fine.
I still wonder if this structure is the best way to have the persistence unit scope set to ear level. I find it strange that I have to create an empty jar just to place persistence.xml at the root level of the ear.
Is there a better way to accomplish this?
Thanks,
Dragos
-
2. Re: Persistence unit issues when migrating to JBOSS 5.1.0
jaikiran Jan 8, 2010 10:01 AM (in response to dbobes)dbobes wrote:
I find it strange that I have to create an empty jar just to place persistence.xml at the root level of the ear.
Is there a better way to accomplish this?
Thanks,
Dragos
Place the persistence.xml in the META-INF of the .ear.
So:
myapp.ear | |--- META-INF | | | |--- persistence.xml
And let the persistence.xml use the "jar-file" element to point to the jars containing the entities. This is how the EJB3 persistence spec lets EAR level persistence.xml to be deployed. For more details, see section 6.2 of EJB3 Persistence spec.
-
3. Re: Persistence unit issues when migrating to JBOSS 5.1.0
dbobes Jan 8, 2010 11:44 AM (in response to jaikiran)Thanks Jaikiran, it makes a lot more sense now. I tried this earlier but it failed because I wasn't using the <jar-file> tag and I ended up thinking this is not the way to do it.
-
4. Re: Persistence unit issues when migrating to JBOSS 5.1.0
jaikiran Jan 15, 2010 7:48 AM (in response to jaikiran)jaikiran wrote:
Place the persistence.xml in the META-INF of the .ear.
So:
myapp.ear | |--- META-INF | | | |--- persistence.xml
And let the persistence.xml use the "jar-file" element to point to the jars containing the entities. This is how the EJB3 persistence spec lets EAR level persistence.xml to be deployed. For more details, see section 6.2 of EJB3 Persistence spec.
For the record - my statement is incorrect. The EJB3 spec doesn't _not_ specify that the persistence.xml can be placed in the META-INF of the .ear. According to the spec, for scoping a persistence unit at ear level, the persistence.xml should be packaged in:
- META-INF of a jar file in the root of the EAR
- META-INF of a jar file in the EAR library directory
Note that although JBoss scans the .ear/META-INF/persistence.xml file, it's _not_ recommend that applications package their persistence.xml in this manner, since it can lead to issues like the one being discussed here http://community.jboss.org/message/520279
-
5. Re: Persistence unit issues when migrating to JBOSS 5.1.0
dbobes Jan 15, 2010 9:03 AM (in response to jaikiran)Hi Jaikiran, I appreciate the time you spent on this issues.- META-INF of a jar file in the root of the EAR
This is how I had the ear in the first place and it didn't work.
If you look at my first post on this discussion the persistence.xml file was located in the META-INF folder of the myseammodule.jar which was located in the root of the ear (also this jar was specified as an ejb module in application.xml). In this case extejbmodule.jar didn't have access to the persistence unit.
- META-INF of a jar file in the EAR library directory
I still have to try this option but right now I encountered another scoping problem. The extejbmodule.jar (from my first post) has a stateless bean defined like this:
@Stateless(name="Server", mappedName="myapp/Server/local")
In the seam's components.xml file I have defined the server component like this:
<component name="server" auto-create="true" scope="event" jndi-name="myapp/Server/local" class="com.company.ServerImpl">
But when I try to inject the component into a seam bean:
@In Server server;
it throws:
javax.naming.NameNotFoundException: Server not bound
In debug, it fails when it tries to lookup the "myapp/Server/local" jndi name. This was not a problem in JBOSS 4.2.3 so it must be also related to the new scoping where entities from one module are not visible to the others.
Any ideas?
-
6. Re: Persistence unit issues when migrating to JBOSS 5.1.0
jaikiran Jan 15, 2010 9:28 AM (in response to dbobes)dbobes wrote:
has a stateless bean defined like this:
@Stateless(name="Server", mappedName="myapp/Server/local")
In the seam's components.xml file I have defined the server component like this:
<component name="server" auto-create="true" scope="event" jndi-name="myapp/Server/local" class="com.company.ServerImpl">
But when I try to inject the component into a seam bean:
@In Server server;
it throws:
javax.naming.NameNotFoundException: Server not bound
The mappedName attribute of @Stateless is _not_ used as the jndi name for binding into JNDI. You will have to use @RemoteBinding (or @LocalBinding) as explained here
-
7. Re: Persistence unit issues when migrating to JBOSS 5.1.0
dbobes Jan 18, 2010 11:19 AM (in response to jaikiran)@LocalBinding solved the lookup problem. Right now the lookup works in both JBOSS 5 and JBOSS 4.
I am still placing the persistence.xml in the ear's META-INF as this is the only way to have the persistence unit shared between ear's modules. I just have to be careful to change the <jar-file> tag to 'myapp.ear/myseammodule.jar' when I deploy it on windows and to 'myseammodule.jar' when I deploy it in unix.
-
8. Re: Persistence unit issues when migrating to JBOSS 5.1.0
bohl Nov 6, 2010 7:19 AM (in response to jaikiran)Sorry for waking up this old thread. I have a question about this:
For the record - my statement is incorrect. The EJB3 spec doesn't _not_ specify that the persistence.xml can be placed in the META-INF of the .ear. According to the spec, for scoping a persistence unit at ear level, the persistence.xml should be packaged in:
- META-INF of a jar file in the root of the EAR
- META-INF of a jar file in the EAR library directory
I'm not sure which document is meant with "EJB3 spec", could you please post a link? If you meant this document http://download.oracle.com/javaee/6/api/ .., I can't find any deployment rules for .ear files in there.
-
9. Re: Persistence unit issues when migrating to JBOSS 5.1.0
jaikiran Nov 6, 2010 9:12 AM (in response to bohl)Lars Bohl wrote:
Sorry for waking up this old thread. I have a question about this:
For the record - my statement is incorrect. The EJB3 spec doesn't _not_ specify that the persistence.xml can be placed in the META-INF of the .ear. According to the spec, for scoping a persistence unit at ear level, the persistence.xml should be packaged in:
- META-INF of a jar file in the root of the EAR
- META-INF of a jar file in the EAR library directory
I'm not sure which document is meant with "EJB3 spec", could you please post a link?
The Final Release document here http://jcp.org/en/jsr/detail?id=220