2020-08-27

Hibernate JPA @TypeDef Example

@TypeDef

The @TypeDef annotation is used to specify a @Type definition which can later be reused for multiple basic attribute mappings.

TypeDef is a type definition. Much like Type, but here we can centralize the definition under a name and refer to that name elsewhere. The plural form is TypeDefs.

@TypeDef to register a custom Type

@Entity(name = "Product")
@TypeDef(
name = "bitset",
defaultForType = BitSet.class,
typeClass = BitSetType.class
)
public static class Product {

@Id
private Integer id;

private BitSet bitSet;

//Getters and setters are omitted for brevity
}

@TypeDefs
The @TypeDefs annotation is used to group multiple @TypeDef annotations.

No comments:

Post a Comment