Skip to main content

@ManyToOne in multiple jars with Glassfish/EclipseLink

Please note these forums are being decommissioned and use the new and improved forums at
2 replies [Last post]
Joined: 2011-02-04

I've got two jars, dog.jar and person.jar, both packaged as ejb modules within a single ear. is an Entity that references another Entity 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] 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 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...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-03-29

Having two persistence.xml defines two persistence units. You can not have relationships across persistence units. I think you can use following packaging



person.jar --> Contains entities (no ejbs) you intended to package in this jar

dog.jar --> Contains entities (no ejbs) you intended to package in this jar

ejb.jar --> contains ejbs that operate over entities defined above and persistence.xml that refers to above jars

Joined: 2011-02-04

But this is a large multi-module enterprise proejct with different develolpers in charge of producing the artifacts associated with person and dog, including the queries in the DAOs.

The "ejb.jar" you have referenced above would subsume both person-dao.jar and dog-dao.jar, and prevent us from developing this app in a modular manner. This is disconcerting and leaves me wondering if JPA is a good choice for my needs... how does a multi-module enterprise app typically approach this issue?