@ManyToOne in multiple jars with Glassfish/EclipseLink [message #686223] |
Tue, 21 June 2011 20:53 |
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 |
|
>> 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03876 seconds