Quillion
Quillion

Reputation: 6476

How to store LocalTime in hibernate

I have an entity that has a variable of type LocalTime and I would like to store it in database. So I have two questions:

  1. What data type will the field in mysql be?
  2. What annotation to use for entity?

I do not care for date at all whatsoever.

Upvotes: 7

Views: 3868

Answers (1)

holi-java
holi-java

Reputation: 30686

hibernate-java8 provide a LocalTimeType for persist a LocalTime field.Since hibernate-java8-5.2.+ has been merged into the hibernate-core module.

Usage

saving LocalTime as sql time column.

@Column
private LocalTime time;

saving LocalTime as sql varchar column.

@Column(columnDefinition = "varchar(8)")
private LocalTime time;

Upvotes: 10

Related Questions