• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA: entity for multiple PU and different DB

 
daniele licitra
Ranch Hand
Posts: 77
Java Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
E Armitage
Rancher
Posts: 989
9
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you create the two persistence units and what error message did you get?
 
daniele licitra
Ranch Hand
Posts: 77
Java Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 989
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what happens if you don't list the entity classes in persistence.xml files?
 
daniele licitra
Ranch Hand
Posts: 77
Java Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same issue


 
E Armitage
Rancher
Posts: 989
9
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the suggested workaround of separating the packages for the gerated meta model using syntax like the below
 
daniele licitra
Ranch Hand
Posts: 77
Java Linux Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic