• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Can you store persistence.xml in an ear file?

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two jars that are included in an ear file. Each jar contains entity classes but neither jar includes a persistence.xml.

I would like the entities in both jars to share the same persistence unit (myPU). So I would like to store the persistence.xml file at the ear level and not the jar level.

I have tried putting the persistence.xml file in the META-INF of the ear and also at the top level of the ear and neither seems to work.

my ear is structured as follows

EAR

META-INF/MANIFEST.MF
META-INF/application.xml
MyEntities1.jar
MyEntities2.jar
persistence.xml
orm.xml

Is it possible to store the persistence.xml in an ear file?
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.ear/META-INF is the right place to put the persistence.xml, if you want it to be available to all components in the .ear. What issues are you running into, if you place it there?
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should need to place at /META-INF/Persistence.xml inside EAR file. It will be available through out the application.
 
Bobby Anderson
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate on my app server (JBoss 4.2.3) is not picking up my entities so it seems like the persistence.xml is not in the correct place. If I put a persistence.xml file in META-INF directory of each jar file with a different unit name hibernate picks up and deploys all my entities. But I want only one unit name (persistence unit) for all my entities even though they are in a different jar.

Is this a problem with JBoss?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Billy Newman wrote:Hibernate on my app server (JBoss 4.2.3) is not picking up my entities so it seems like the persistence.xml is not in the correct place.



You need to specify the entity jar files in the persistence.xml. The persistence.xml xsd allows for multiple jar-file elements where you can specify those jar files. The other details can be found here
 
Bobby Anderson
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just as I suspected you cannot do this in jboss 4

This is from the link you posted:


4.2.2. persistence.xml and .jar files

For those of you familiar with older versions of the spec, there is no .par file anymore. Entities are placed in a EJB-JAR .jar file or a .jar file all their own. You must also define a persistence.xml file that resides in the META-INF folder of the .jar file. Here's an example of a persistence.xml file.



and


4.3. EAR and WAR files

JBoss 4.0.x does not support the Java EE 5 EAR format. So, if you want to deploy a standalone persistence archive, you must list it within application.xml as an ejb module.

For WAR files, JBoss 4.0.x does not yet support deploying a persistence archive with WEB-INF/lib as required by the spec.



Although it does say Jboss 4.0.x does not support Java EE Ear format, but since I cannot get this to work my guess is that JBoss 4.2.x also does not support it.


Oh well I guess at least I know this is a JBoss limitation.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am some what sure that packaging in the .ear/META-INF was supported in AS 4.2.x. The jar-file entry would point to the correct jars. But it's been a very long time now since i have played with 4.x versions. If it's feasible, move to the latest stable 5.1.0 of AS which is fully compliant with the spec.
 
Bobby Anderson
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is worth a try. I will try will the jar file in the persistence.xml file to see if that helps. I will edit this reply to let everyone know what I find.

Thanks for your help!
 
Bobby Anderson
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No luck, got the following from jboss log


2009-12-15 09:06:46,899 INFO [org.jboss.deployment.EARDeployer] Init J2EE application: file:/opt/jboss-4.2.3.GA/server/all/farm/test.ear
2009-12-15 09:06:46,902 DEBUG [org.jboss.deployment.EARDeployer] Extracted non-deployable content: META-INF/MANIFEST.MF
2009-12-15 09:06:46,902 DEBUG [org.jboss.deployment.EARDeployer] Extracted non-deployable content: META-INF/application.xml
2009-12-15 09:06:46,903 DEBUG [org.jboss.deployment.EARDeployer] Extracted deployable content: MyEntities1.jar
2009-12-15 09:06:46,903 DEBUG [org.jboss.deployment.EARDeployer] Extracted deployable content: MyEntities2.jar
2009-12-15 09:06:46,903 DEBUG [org.jboss.deployment.EARDeployer] Extracted non-deployable content: META-INF/persistence.xml
2009-12-15 09:06:46,904 DEBUG [org.jboss.deployment.EARDeployer] Extracted non-deployable content: META-INF/orm.xml



here is my new persistence.xml file:


here is my ear file listed:


0 Tue Dec 15 09:03:58 MST 2009 META-INF/
106 Tue Dec 15 09:03:56 MST 2009 META-INF/MANIFEST.MF
664 Tue Dec 15 08:57:20 MST 2009 META-INF/application.xml
17330 Tue Dec 15 08:53:54 MST 2009 MyEntities1.jar
12191 Tue Dec 15 08:53:44 MST 2009 MyEntities1.jar
2167 Tue Dec 15 09:03:40 MST 2009 META-INF/persistence.xml
424 Mon Dec 14 12:03:44 MST 2009 META-INF/orm.xml



here is a snippet from my application.xml file:


Do I still store the entity jars at the top level?

I cannot switch to jboss 5 so I am stuck with re-packaging all entities in one jar if I cannot get this to work

I will look around to see if JBoss 4.2.3 will allow this, if anyone has any more ideas please let me know

Thanks!
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic