@ManyToOne in multiple jars with Glassfish/EclipseLink [message #686223] |
Tue, 21 June 2011 16:53  |
Eclipse User |
|
|
|
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 #687972 is a reply to message #687962] |
Thu, 23 June 2011 11:30  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03910 seconds