File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes JPA: entity for multiple PU and different DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JPA: entity for multiple PU and different DB" Watch "JPA: entity for multiple PU and different DB" New topic
Author

JPA: entity for multiple PU and different DB

daniele licitra
Greenhorn

Joined: Apr 08, 2013
Posts: 27

Hi to all.

I have a package (JAR_A) for entity and controller definition, for example:
entity: Entity
controller: EntityController

Then I use this jar in other projects/applications that use the entity.

I want to use the same JAR_A with different persistence unit and different database (in particular, mysql and postgresql) but when I define two persistence unit that include the same class, I have an exception.
So, I comment the other PU and compile the project.

there is a smarter way for use same package with different PU ?


JPA 2.1.0
Glassfish 3.1, Primefaces 3.4
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 761
    
    9
How did you create the two persistence units and what error message did you get?
daniele licitra
Greenhorn

Joined: Apr 08, 2013
Posts: 27

I'm sorry, I did not explain the situation in the right way.

I have at least 3 package:
- the first package (it's a maven project) contains a "superclass" entity

It defines the basic field of an entity and the relative getter and setter.

Inside the POM I define a plugin to enhance the class using datanucleus:

The plugin enhance the StandardEntity using the abstract persistence unit:

If the PU is like above, it works.

- the second package use the first and define software specific entity:

the pom is:


and the PUs are:


Even if I specified in the POM plugin only a PU, i get the following error:

An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.RuntimeException: javax.annotation.processing.FilerException: Attempt to recreate a file for type com.bss.easycooking.libdataeasycooking2.entity.BaseRicette_
at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:407)
...
Caused by: javax.annotation.processing.FilerException: Attempt to recreate a file for type com.bss.easycooking.libdataeasycooking2.entity.BaseRicette_
at com.sun.tools.javac.processing.JavacFiler.checkNameAndExistence(JavacFiler.java:522)


i found this page:
https://netbeans.org/bugzilla/show_bug.cgi?id=194605
The problem is that the same entity can't stay in two PU...the class first is enhanced for PU1 and then for PU2 but files already exists.

So, is a possible solution to create two plugin, one for PU, and create two JAR, *-mysql.jar and *postgresql.jar ?
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 761
    
    9
what happens if you don't list the entity classes in persistence.xml files?
daniele licitra
Greenhorn

Joined: Apr 08, 2013
Posts: 27

Same issue


E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 761
    
    9
Try the suggested workaround of separating the packages for the gerated meta model using syntax like the below
daniele licitra
Greenhorn

Joined: Apr 08, 2013
Posts: 27

E Armitage wrote:Try the suggested workaround of separating the packages for the gerated meta model using syntax like the below


It worked with the two different subpackage! Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA: entity for multiple PU and different DB
 
Similar Threads
Can we declare same entity in two or more persistence units?
Dirty read (?) problem
Best practice for persistence unit
Integrate multiple JPA projects
EJB can't find Optional Package and thus Persistence Unit in it