I've been playing with annotations. I like much about them, although embedded objects tend to get a big bloated with all the overriding information.
I am having some trouble with one thing. I have a DomainObject base class that all my objects extend from. This is a common pattern I've used for years. I have used @MappedSuperclass on DomainObject to allow Hibernate to read my properties, and that works. However, I am getting a weird error for the name of the "id" column. It thinks that I am repeating it.
If I get rid of the id in DomainObject and put it in my subclass directly, and then name the column from "id" to "my_class_id", the error goes away.
Is there any way to have the methods and everything in the base class, but then specialize the name of the identifier property in the subclass, or do I need to repeat the id in every domain object?
The reason this is important is that I have some methods in DomainObject that act on the ID... and I guess I'd rather operate on the private variable than abstract property methods.
Code:
@MappedSuperclass
public abstract class DomainObject implements Serializable {
/* Members */
@Id
@GeneratedValue
@Column( name = "id" )
protected Long id;
@Column( name = "is_active" )
protected boolean isActive = true;
/* Constructors */
/* Services */
public boolean isTransient() {
return getId() == 0;
}
/* Properties */
public Long getId() {
return id;
}
public void setId( Long id ) {
this.id = id;
}
public boolean isActive() {
return isActive;
}
public void setActive( boolean active ) {
isActive = active;
}
}