Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
762 views
in Technique[技术] by (71.8m points)

jpa - Fix for Hibernate error "Use of the same entity name twice"

How you fix the following Hibernate error:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This exception occures when you have more then one @Entity with the same class's name or explicit name. To fix the issue you have to set different explicit names for each entity.

Example of error case:

package A;

@Entity
class Cell{
 ...   
}


package B;

@Entity
class Cell{
 ...   
}

Solution example: package A;

@Entity(name="a.Cell")
class Cell{
 ...   
}


package B;

@Entity(name="b.Cell")
class Cell{
 ...   
}

So, to use them in HQL you have to write

...createQuery("from a.Cell")...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...