Reputation: 3206
@Entity(name="myEntity")
which is used in JPQL shall be unique per persistence unit.
@Table
defines SQL name of the database table for storing my entity (default name being just unqualified class name). But without specifying scheme this name shall be unique for the entire database.
What if my application uses a single database and different packages use/persist JPA @Entity
classes with the same name? I guess I have to make table names unique, so I need to qualify all other entity classes with the same name with @Table(name="somePrefix_MyDuplicateClassName")
, or specify scheme like @Table(name="MyDuplicateClassName", schema="specific_Schema_To_Distinguish_Same_ClassNames")
right? Concerning schema - I guess it is possible to run into having no privileges to create new schemas, besides not all databases support it. Is schema solution ever used in such situations?
What are the exact requirements of @Table name uniqueness? What shall be done in such situations in practice?
I find nothing googling and reading JPA specification...
Upvotes: 0
Views: 721
Reputation: 5095
In the @Entity
annotation you can specify a different name to achieve uniqueness like so @Entity(name = "MyDuplicateEntity")
. This does not reflect on the @Table
in any way.
Upvotes: 0