Hibernate Version 5.0

Date/Time API

Hibernate supports the classes of the Date and Time API as BasicTypes. This provides the main advantage, that you don’t have to provide any additional annotations. Not even the @Temporal annotation which you currently add to each java.util.Date attribute.

Hibernate 5 is the first version which supports the Java 8 Date/Time API. Developers can use Java8 Date/Time in the program and persistence will be handled well by the ORM. It means in persistence Process below thing is taken care by ORM.

@ Repetable annotations

It is actually used to annotate the same annotation multiple times. For example, you can define multiple named queries under @NamedQueries annotation.


Load Object by Multiple IDS

Method byMultipleIds(), which is part of the session class and this is used to load multiple objects at a time by providing the primary key in multiLoad() function. This is very useful when we know about the primary key and want to load all at a time in the list.

MultiIdentifierLoadAccess<Employee> multi = session.byMultipleIds(Employee.class);
List<Employee> student= multi.multiLoad(1L, 2L, 3L);

Support for Stream query results 

Stream (): This method is used to efficiently implement usage cases where large quantity is to be retrieved. if you’re working on a huge result set, you better scroll through the result records and fetch them in smaller chunks. You’re already familiar with that approach if you’ve used JDBC result sets or Hibernate’s ScrollableResult. Scrolling through the records of a result set and processing them as a Stream is a great fit. Both approaches process one record after the other, and there’s no need to fetch all of them upfront. The Hibernate team, therefore, decided to reuse the existing scroll()method and the ScrollableResult to implement the new stream() method.  

Joining unassociated entities in a query

Hibernate 5.1 introduced explicit joins on unrelated entities. The syntax is very similar to SQL and allows you to define the JOIN criteria in an ON statement. Instead of referencing the attribute which defines the relationship between the two entities, you have to reference the second entity which you want to join and define the join criteria in the ON part of the statement. 

The only way to join two unrelated entities with JPA 2.1 and Hibernate versions older than 5.1, is to create a cross join and reduce the cartesian product in the WHERE statement. 



Comments

Popular posts from this blog

Maven Setting Mirror

Spring Session