Hibernate Annotations

compared with
Current by Fiona Malikoff
on Nov 05, 2018 20:14.

(show comment)
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (7)

View Page History

h4. Entity and Table Annotations For Class
@Table(name = "lams_learning_activity")

If the object is the root of an inheritance hierachy then add

@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "learning_activity_type_id", discriminatorType = DiscriminatorType.INTEGER)

Then in the subclass add the Discriminator

h4. Id field
Add a @Column annotations for all other persistent fields. Just use name and columnDefinition options. Name is required (and should be omitted) if the name of the field is identical to the name of the column. If you want to note anything special about the column use the columnDefinition option. The column definition and the other options (length, type, etc) are only for DDL so no point meticulously recording them all when we maintain the database manually - we just risk the definitions in the code getting out of sync with the database.

If the field is the DiscriminatorColumn (see above) then use:

@Column(name = "learning_activity_type_id", insertable = false, updatable = false)

h4. Transient Annotation