I am doing a migration of old project (Core Java + EJB + hibernate) from hibernate 3 to hibernate 5.2.12. Though hibernate 5.2.12 supports .hbm.xml file but as a part up gradation migrating from .hbm files to Annotated files.
Below is the scenario i have, and the data model is tightly coupled classes.
public interface BaseEntity extends Serializable, Cloneable, Observable
{
public void setId(long id);
public long getId();
... few other generic attributes
}
public class BaseClass implements BaseEntity {
protected long id;
public void setId(long id)
{
this.id = id;
}
public long getId()
{
return objectId;
}
.. few other attributes
}
public class AuditableBaseClass extends BaseClass implements BaseEntity, Audit
{
... few other attributes
}
public class Car extends AuditableBaseClass {
.... some attributes
}
public class Bike extends AuditableBaseClass {
...some attributes
}
public class Truck extends AuditableBaseClass {
... some attributes
}
If we look at the existing .hbm.xml file below, Used different sequence for the different classes
<class name="Car" table="Car">
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">SEQ_CAR</param>
</generator>
</id>
<
// some other properties
</class>
<class name="Bike" table="Bike">
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">SEQ_BIKE</param>
</generator>
</id>
// some other properties
</class>
<class name="Truck" table="Truck">
<id name="objectId" type="long" column="id">
<generator class="sequence">
<param name="sequence">SEQ_TRUCK</param>
</generator>
</id>
</class>
Simple definition for @Id using sequence is as below
@Id
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "sequence-generator" )
@SequenceGenerator( name = "sequence-generator", sequenceName = "SEQ_NAME" )
For a fact that i know we need to use @MappedSuperclass
to represent the super class. How to represent sequence attribute for an @Id column which is using a different sequence for different child classes though all classes inherit the attribute id but uses different sequences for each.
Any help on this please?