This file contains hidden or 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 String value; |
This file contains hidden or 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
Book b = new Book(); | |
b.setTitle(“The Hound of the Baskervilles”); | |
b.setPublishingDate(LocalDate.of(1902, 4, 30)); | |
em.persist(b); |
This file contains hidden or 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
StoredProcedureQuery q = this.em.createNamedStoredProcedureQuery(“getReviews”); | |
q.setParameter(2, b.getId()); | |
List<Review> reviews = q.getResultList(); |
This file contains hidden or 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 Author { | |
… | |
@Column | |
private LocalDate dateOfBirth; | |
public int getAge() { | |
return return Period.between(dateOfBirth, LocalDate.now()).getYears(); |
This file contains hidden or 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(name = “BlogPost”) | |
public class BlogPost extends Publication { | |
@Column | |
private String url; | |
… | |
} |
This file contains hidden or 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
Session session = em.unwrap(Session.class); | |
SessionFactory sessionFactory = em.getEntityManagerFactory().unwrap(SessionFactory.class); |
This file contains hidden or 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 | |
@Immutable | |
public class BookView { | |
… | |
} |
This file contains hidden or 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
Statistics stats = sessionFactory.getStatistics(); | |
long queryCount = stats.getQueryExecutionCount(); |