Minutis
Minutis

Reputation: 1202

Same table name for two JPA persistence units with NetBeans

My persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="first" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>database.first.entity.Grupe</class>
        <properties>
             <property name="javax.persistence.jdbc.url" value="jdbc:mysql://*****/first"/>
             <property name="javax.persistence.jdbc.password" value="*****"/>
             <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
             <property name="javax.persistence.jdbc.user" value="*****"/>
        </properties>
    </persistence-unit>
    <persistence-unit name="second" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>database.second.entity.Darbuotojas</class>
        <class>database.second.entity.Grupe</class>
        <properties>
              <property name="javax.persistence.jdbc.url" value="jdbc:mysql://*******/second"/>
              <property name="javax.persistence.jdbc.password" value="*****"/>
              <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
              <property name="javax.persistence.jdbc.user" value="*****"/>
        </properties>
    </persistence-unit>
</persistence>

As you see there is one Grupe class in each persistence unit. But when I try to create two @Entity classes with same Grupe name (but in different packages, therefore this shouldn't be a problem) NetBeans gives me error:

Duplicated entity name. Class database.first.entity.Grupe is using the same name.

Is there any annotations witch could solve this problem, because I don't want to create classes with different class names like GrupeFirst and GrupeSecond.

Upvotes: 0

Views: 2316

Answers (1)

James
James

Reputation: 18379

It should be ok if they are in different persistence units.

Try setting to true, it might be finding both classes because they are in the same jar file.

Instead of renaming the class you can also just set the name on the @Entity to a different name.

Upvotes: 1

Related Questions