tags:

views:

1051

answers:

3

How you fix the following Hibernate error:

What does "Use of the same entity name twice".

A: 

I think it means you have declared the same entity in more than one configuration file.

Without more information, I would try commenting out chunks of your config file so that you don't see the error, and then slowly adding sections back in until you encounter the error?

If its only a few config files, then why not post them here? When posting, if you add 4 spaces to the front of your XML, then it will be:

<xml>nicely formatted</xml>

Hope this helps.

toolkit
A: 

One of the most common mistakes you could make to produce this error is to attempt to persist two different Java classes in identically-named tables. Hibernate likes there being exactly one kind of thing in each table (with some exceptions for subclasses and the like), and so if you were to create a class called maybe StudentRecord and a class called MusicRecords, and if you then told Hibernate to persist both of those classes into a table called "records", you could produce that kind of exception. With that particular wording, I suspect you're using annotations (in which case it's even easier to accidentally name two tables, described in two different Java classes, the same thing).

Hope this helps! (although perhaps not, as I have noticed just now that you asked this question 7 months ago. I do hope you're not still stuck, sir!)

CaptainAwesomePants
+2  A: 

I've come across this error a few different times. The causes were as follows:

  1. I had a duplicate mapping in my hibernate configuration (check config file/code)
  2. Two threads were attempting to build the HibernateSessionFactory object at the same time. A synchronized lock on the initialization code fixed this.
  3. An attempt to build the HibernateSessionFactory failed, but is being called again. The Hibernate Configuration object didn't get cleared out, so the entities are being processed again.
  4. You have two entity classes being mapped to the same file. Hibernate will choke on this as well.
Adam Hawkes