This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes JPA Certification (OCEJPA) and the fly likes Entity name must be unique in a persistence unit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Certification » JPA Certification (OCEJPA)
Bookmark "Entity name must be unique in a persistence unit" Watch "Entity name must be unique in a persistence unit" New topic

Entity name must be unique in a persistence unit

Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 84

I am hoping you could kindly help me with the error I am encountering as describe below.

I am trying to separate my entities via package, like the following below:

- manyToManyMap.model.Employee
- overrideCollectionTableColumn.model.Employee

And I am trying to define a separate persistence-unit in my persistence.xml for each package, please see below:

But went I tried to deploy it in Glassfish 3.1 from Eclipse (Juno) the following error prompts:

I am not sure if this is a bug, or I am missing something in JPA 2.0. I already tried to provide different name for each "Employee" entity, but there was an error in persisting an object.

Is there a work around for these scenario, or I might just need to create a separate project for each persistence unit.

Thank you in advance for your insights, time and assistance.

Dennis Grimbergen
Ranch Hand

Joined: Nov 04, 2009
Posts: 148

Edit: Now I see you already tried this:
You can set the name of an entity explicitely by specifying it in the @Entity annotation like:


If you omit the name attribute then the class name of the entity is taken as it name. In your case both 'Employee' (even though both entities were in different packages).

What error did you get in persisting an entity?

subject: Entity name must be unique in a persistence unit