Reputation: 5609
I have two tables, both named Language in two different schemas, lets call them schema1 and schema2.
When I annotate the models for each of these tables, my code looks like this: @Entity @Table(name="language", catalog="schema1") public class Language {
.....................
@Entity
@Table(name="language", catalog="schema2")
public class Language {
But when doing this, I get an annotation Exception error as follows:
org.hibernate.AnnotationException: Use of the same entity name twice: Language
So, does this mean I can't have identically named tables in two different database schemas or am I just annotating my models wrong?
Thank you,
Elliott
Upvotes: 3
Views: 2657
Reputation: 111
I've had the same issue, in a complex class structure, and the answer above is just a workaround. You can define the @Entity annotation with a name variable to distinguish the two classes from each other. Ex:
Class 1:
@Entity(name="language_v1")
@Table(name="language", catalog="schema1")
public class Language {
Class 2:
@Entity(name="language_v2")
@Table(name="language", catalog="schema2")
public class Language {
This will allow you to keep your class structure.
Upvotes: 4
Reputation: 5609
It turns out that the model in schema 2 was an object that was an extension of the model object in schema 1. Hibernate does not like this kind of construction when the two tables are named the same. Making the second object not an extension of the first, eliminated the problem.
Upvotes: 0