Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate and java 8 lambda's

Since the introduction of Java 8, is Hibernate waiting some changes? specially

  1. Is there any way to write queries with lambdas in Hibernate? (i.e. like a .net Linq-to-SQL style)

  2. If not, when it's coming (If it's planned to come).

for example something like these:

User u1 = dbo.Users.firstOrDefault(f -> f.userId = 10);

List<User> users = dbo.Users.selectMany(w -> w.userId > 5);
like image 996
RustamIS Avatar asked Jul 03 '14 20:07

RustamIS


1 Answers

I thought it could not be done too. But I saw Jinq http://www.jinq.org/ They do it for raw SQL queries.

database.customerStream().where(
customer -> customer.getName().equals("Alice"));

So I think it just depends on someone implement the same kind of logic being used in Jinq for JPA entities, and generate JPQL queries.

UPDATE: They do it for JPA too. http://www.jinq.org/docs/gettingstartedjpa.html

like image 106
digao_mb Avatar answered Nov 09 '22 22:11

digao_mb