3

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

1
  • Did you try to use schema attribute of Table annotation instead of catalog? Commented Nov 1, 2011 at 16:56

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.