Hibernate JPA @MapKeyType Example

@MapKeyType

The @MapKeyType annotation is used to specify the map key type.

MapKeyType
Allows defining the type of the key of a persistent map.

@MapKeyType mapping example

@Entity
@Table(name = "person")
public static class Person {

@Id
private Long id;

@ElementCollection
@CollectionTable(
name = "call_register",
joinColumns = @JoinColumn(name = "person_id")
)
@MapKeyType(
@Type(
type = "org.hibernate.userguide.collections.type.TimestampEpochType"
)
)
@MapKeyColumn( name = "call_timestamp_epoch" )
@Column(name = "phone_number")
private Map<Date, Integer> callRegister = new HashMap<>();

//Getters and setters are omitted for brevity

}

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation