Forums Register Login

JPA: entity for multiple PU and different DB

+Pie Number of slices to send: Send
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 ?
1
+Pie Number of slices to send: Send
How did you create the two persistence units and what error message did you get?
+Pie Number of slices to send: Send
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 ?
+Pie Number of slices to send: Send
what happens if you don't list the entity classes in persistence.xml files?
+Pie Number of slices to send: Send
Same issue


1
+Pie Number of slices to send: Send
Try the suggested workaround of separating the packages for the gerated meta model using syntax like the below
+Pie Number of slices to send: Send
 

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
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 9149 times.
Similar Threads
Best practice for persistence unit
Dirty read (?) problem
Can we declare same entity in two or more persistence units?
Integrate multiple JPA projects
EJB can't find Optional Package and thus Persistence Unit in it
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:18:53.