chris01
chris01

Reputation: 12311

JPA: one Entity but different tables

Lets say I have an JPA entity. As far I know it is related to exactly 1 DB-table.

@Entity
@Table(name = "ARTICLES")
public class Article
//...

Is it possible to have 1 entity but the table-name would be a parameter I can specify at runtime?

So multiple tables would exist - all with the same layout.

Upvotes: 0

Views: 325

Answers (1)

Panagiotis Bougioukos
Panagiotis Bougioukos

Reputation: 18899

JPA is based on ORM (Object Relational Mapping). It is used to map a java object to a database table.

Your requirement if understood well is 1 java object but multiple tables. I think that this goes out of JPA scope. Even if you provided the name of the table during runtime, what would be the java object that would be mapped ?

That would be achievable with raw JDBC though.

Upvotes: 1

Related Questions