Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @ManyToOne in multiple jars with Glassfish/EclipseLink
@ManyToOne in multiple jars with Glassfish/EclipseLink [message #686223] Tue, 21 June 2011 20:53 Go to next message
Kevin Pauli is currently offline Kevin Pauli
Messages: 6
Registered: June 2011
Junior Member
I've got two jars, dog.jar and person.jar, both packaged as ejb modules within a single ear. Dog.java is an Entity that references another Entity Person.java via a OneToMany mapping on an "owner" field. Each jar has its own persistence.xml, which reference a common persistence unit, but each persistence.xml only contains the classes contained in that jar.

Upon startup, Glassfish complains:

Exception Description: [class com.example.dog.entities.Dog] uses a non-entity [class com.example.person.entities.Person] as target entity in the relationship attribute [field owner].


It seems to work if I add the Person class to the dog jar's persistence.xml, but I don't like that at all. The Person class is already defined in the persistence.xml of the person.jar, which is in same named persistence unit, in the same ear, so it should find it at runtime! I don't want to repeat myself.

Plus, I use the handy Eclipse JPA tooling to auto-sycnhronize the class names in the persistence.xml, and when I do that it only finds the Dog.java when I run it on dog's persistence.xml. So I don't want to have to hunt down all references and manually add them to persistence.xml and worry about them getting blown away when I resynchronize.

Also I made sure I put the person ejb module before the dog ejb module in the application.xml.

This is my first foray into JPA and JEE, so I could be doing something wrong... I drank the koolaid by reading books and articles but nobody seems to ever show a good mutli-module enterprise example...
Re: @ManyToOne in multiple jars with Glassfish/EclipseLink [message #687962 is a reply to message #686223] Thu, 23 June 2011 15:19 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

>> persistence.xml, which reference a common persistence unit

You can only have a single persistence.xml for a persistence unit.
You either need two separate persistence unit, or only a single persistence.xml.
You can list the dog.jar from the person persistence unit, or create another persistence-unit.jar that just has the persistence.xml and reference both jars.

You may also want to look into EclipseLink composite persistence units.


James : Wiki : Book : Blog : Twitter
Re: @ManyToOne in multiple jars with Glassfish/EclipseLink [message #687972 is a reply to message #687962] Thu, 23 June 2011 15:30 Go to previous message
Kevin Pauli is currently offline Kevin Pauli
Messages: 6
Registered: June 2011
Junior Member
Ah. I was under the mistaken impression that just by referencing the same persistence unit name, that at runtime it would somehow merge all the references, allowing us to have two different teams work on the two different modules.

Composite persistence units! That may be the key I am looking for! I shall look at that during a future iteration of this project.

No more time now though... so for now I have mitigated the issue by putting the entities in jars in the ear lib, and merging all the DAOs and the persistece.xml into a new combined cross-module EJB project. It is not ideal b/c I really wanted to keep the development of the different modules separate, including the persistence layer, but it works for now.
Previous Topic:(no subject)
Next Topic:Connection pooling and network timeouts
Goto Forum:
  


Current Time: Fri Oct 31 15:14:37 GMT 2014

Powered by FUDForum. Page generated in 0.02064 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software