Fix for Hibernate error “Use of the same entity name twice”

前端 未结 6 901
灰色年华
灰色年华 2020-12-17 17:29

How you fix the following Hibernate error:

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

6条回答
  •  自闭症患者
    2020-12-17 17:58

    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!)

提交回复
热议问题