Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Hibernate support for Java 8 features
PostPosted: Wed Apr 13, 2016 9:25 am 
Newbie

Joined: Wed Apr 13, 2016 9:18 am
Posts: 5
Hi,

Can somebody please give me a overview on which Java 8 features are (or will be) covered in which Hibernate ORM version?
We are planning a major upgrade on our software architecture in context of Java 8.
I do know that since Hibernate 5 there is 'java8' support, but it's not clear to me which features are actual covered.

Second question: is it possible to enable (via extra libraries) all or some Java 8 features on Hibernate?


Top
 Profile  
 
 Post subject: Re: Java 8 features support
PostPosted: Wed Apr 13, 2016 11:27 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1537
Location: Romania
There is a new module for Java 1.8 features:

Code:
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-java8</artifactId>
    <version>${hibernate.version}</version>
</dependency>


and it supports Java 1.8 Date/Time types.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Java 8 features support
PostPosted: Wed Apr 13, 2016 1:25 pm 
Newbie

Joined: Wed Apr 13, 2016 9:18 am
Posts: 5
hi,

Thanks for that but i allready knew that. In fact, i've looked into the actual jar and imho it only contains types for JSR310 (date-time api).

But what about all other Java 8 features, what about: Optional, lambda's in queries, Stream(ing) opportunities in Results, maybe Parallel arrays, etc.
Isn't there some kind of summary/matrix which can indicatie, per feature, if it is supported and if so, in which hibernate version/artifact?

I actually need to decide, in context of Java 8 support, if it's worth upgrading to ORM 5.

If there is no consolidated overview or summary available (yet), i gladly welcome individual links too !

Kind regards,
And TIA!

-wil-
@WimLambrecht


Top
 Profile  
 
 Post subject: Re: Java 8 features support
PostPosted: Wed Apr 13, 2016 1:33 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1537
Location: Romania
That Jira issue is almost like a matrix. All in all, there is a plan to support Money and Currency.
Optional is not meant for Entities, as it's not Serializable. You can still use it in methods if you want.
Stream, you can use them with any Collection, just like with any other Java collection.

The best reason for migrating is the new feature list and the new User Guide.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Java 8 features support
PostPosted: Wed Apr 20, 2016 8:21 am 
Newbie

Joined: Wed Apr 13, 2016 9:18 am
Posts: 5
Ok, thank for the reply. I'll look into the Jira issues.


Top
 Profile  
 
 Post subject: Re: Java 8 features support
PostPosted: Wed Jul 26, 2017 7:31 am 
Newbie

Joined: Wed Jul 26, 2017 7:09 am
Posts: 3
vlad wrote:
That Jira issue is almost like a matrix. All in all, there is a plan to support Money and Currency.
Optional is not meant for Entities, as it's not Serializable. You can still use it in methods if you want.
Stream, you can use them with any Collection, just like with any other Java collection.

The best reason for migrating is the new feature list and the new User Guide.


Are stream operations (e.g. filter) on lazy collections inside of entities translated to appropriate SQL queries as with Linq-To-NHibernate? If not, is such a feature planned? I couldn't find any information about this. Coming from a .NET background I noticed that this feature considerably eases DDD.


Top
 Profile  
 
 Post subject: Re: Java 8 features support
PostPosted: Wed Jul 26, 2017 8:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1537
Location: Romania
Can you give me an example? Is it the list.stream().filter(...) kind of operation that you want to be optimized?

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Java 8 features support
PostPosted: Wed Jul 26, 2017 10:15 am 
Newbie

Joined: Wed Jul 26, 2017 7:09 am
Posts: 3
Filter and maybe some other basic operations. NHiberante additionally supports OrderBy or Last and First for example. This is useful if an entity has a huge collection associated, but only ever wants specific items from the collection.

For example consider a User entity with associated Orders. Over time a user may accumulate a large amount of Orders, i.e. loading them into memory completely would be expensive. We are only ever interested in small subsets of the Orders, e.g. the newest three Orders. With NHibernate this could be done in business code by filtering the Orders collection in the User object, e.g.
Code:
this.Orders.Take(3)
to retrieve the desired subset and NHibernate would translate the LINQ calls to SQL as needed. This way the code is easily testable as it is more persistance ignorant and the domain objects need less orchestration code to perform the queries, e.g.
Code:
repository.retrieveNewestOrders()
.

Maybe I am just stuck to this way of thinking though. Suggestions for alternatives or improvements are also welcome :).


Top
 Profile  
 
 Post subject: Re: Java 8 features support
PostPosted: Wed Jul 26, 2017 3:10 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1537
Location: Romania
But mapping huge collections is a code smell.

You are better off using a @ManyToOne side and just use a JPQL query with LIMIT clause.

We don't support Java 8 stream operations that translate to SQL clauses while fetching data from a Stream. We only support the Stream as a database cursor, but it's not as efficient as pagination.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Java 8 features support
PostPosted: Thu Jul 27, 2017 12:54 pm 
Newbie

Joined: Wed Jul 26, 2017 7:09 am
Posts: 3
Thanks for the clarification! That answers all my questions


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.