Hibernate Annotations

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

(show comment)
Key
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
{code}
@Entity
@Table(name = "lams_learning_activity")
{code}

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

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

Then in the subclass add the Discriminator
{code}
@DiscriminatorValue("2")
{code}

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:

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

h4. Transient Annotation