-
-
Save roamingthings/1398eba69619b6344bad2b7c6ce552cd to your computer and use it in GitHub Desktop.
Persisting Java 8 DateTime API with Hibernate 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class MyEntity { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = "id", updatable = false, nullable = false) | |
private Long id; | |
@Column | |
private LocalDate date; | |
@Column | |
private LocalDateTime dateTime; | |
@Column | |
private Duration duration; | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EntityManager em = emf.createEntityManager(); | |
em.getTransaction().begin(); | |
MyEntity e = new MyEntity(); | |
e.setDate(LocalDate.now()); | |
e.setDateTime(LocalDateTime.now()); | |
e.setDuration(Duration.ofDays(2)); | |
em.persist(e); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.hibernate</groupId> | |
<artifactId>hibernate-java8</artifactId> | |
<version>5.1.0.Final</version> | |
</dependency> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment