We are trying to model the lightweight class design pattern as mentioned in
http://www.hibernate.org/41.html using annotations.
This is how it is done in xml mapping as explained in the given URL.
Code:
<class name="DocumentInfo" table="DOCUMENTS">
<id name="key" type="long" column="ID">
<generator class="native"/>
</id>
<property name="name"/>
<property name="created"/>
<property name="updated"/>
<many-to-one name="folder"/>
</class>
<class name="Document" table="DOCUMENTS" polymorphism="explicit">
<id name="key" type="long" column="ID">
<generator class="native"/>
</id>
<property name="name"/>
<property name="created"/>
<property name="updated"/>
<many-to-one name="folder"/>
<property name="text"/>
</class>
So what we did in annotation was as follows
Code:
@Entity
@Table(name = "objects")
@MappedSuperclass
public class SuperClass {
@Id
private Integer id;
@Column(name = "super_property")
private String superProperty;
.......... // omitting getters and setters for the properties
}
@Entity
@Table(name = "objects")
@org.hibernate.annotations.Entity(polymorphism = PolymorphismType.EXPLICIT)
public class SubclassOne extends SuperClass {
@Column(name = "subclass_one_property")
private String subclassOneProperty;
.......... // omitting getters and setters for the properties
}
In our case everything is working perfectly well. However, we have annotated
the superclass with both @MappedSupperClass and @Entity annotations.
Is it the correct way to model the lightweight class pattern in annotation?