Reputation: 505
Could be possible change the name of the Entity variable ID in JPA? Currently, the DAO save method use the Entity ID. We have multiple existing tables in our database and then, we will have to add the ID column to all tables. Is there any way I can avoid adding the fields? I suppose one possibility will be to override the DAO methods, but any other ideas? Thanks in advance.
Upvotes: 4
Views: 16119
Reputation: 21113
So your entity is defined as:
@Entity
public class SomeEntity {
@Id
private Integer id;
//...
}
You don't have to name the variable id
unless you really want to. You could name this someEntityId
and JPA nor Hibernate cares. The only influence the property name will have is how the NamingStrategy implementation will map that to a column name in the database.
We can override the naming strategy and apply specific names to columns if we need where cases exist that the naming strategy doesn't work for us.
@Id
@Column(name = "some_entity_id")
private Integer id;
This essentially will map the id
variable to a column named some_entity_id
.
Hope that helps.
Upvotes: 15