clougioc clougioc - 3 months ago 14x
Java Question

How to generate name of ID in base object in Hibernate

I have base object for all my entity:

public class BaseObject {

@Column(name = "entity_id")
private Long id;

* @return true if the entity hasn't been persisted yet
public boolean isNew() {
return id == null;

public Long getId() {
return id;

public void setId(Long id) { = id;

The problem is, that I need unicate name for id.

Like this:

user_id, car_id, cat_id

I dont know, how to do it, can you help me?

Its possible override anotation
Column(name = "entity_id")
in child class?

public class User extends BaseObject
public class Car extends BaseObject
public class Cat extends BaseObject


Yes... you need to use @AttributeOverride annotation on each subclass. For example,

@AttributeOverride(name="id", column=@Column(name="user_id"))
public class User extends BaseObject { ... }