JPA Implementations – Which one is the best to use? [closed]

I had the same conclusions about these implementations. OpenJPA was/seemed buggy Hibernate had tons of libraries and seemed to have trouble with not lazy loading everything. Toplink ended up as my choice. It was not as flexible as Hibernate would have been but it works and I don’t have to install commons-logging. The one I … Read more

JPA Criteria builder IN clause query

This criteria set-up should do the trick: CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Employee> q = cb.createQuery(Employee.class); Root<Employee> root = q.from(Employee.class); q.select(root); List<String> parentList = Arrays.asList(new String[]{“John”, “Raj”}); Expression<String> parentExpression = root.get(Employee_.Parent); Predicate parentPredicate = parentExpression.in(parentList); q.where(parentPredicate); q.orderBy(cb.asc(root.get(Employee_.Parent)); q.getResultList(); I have used the overloaded CriteriaQuery.where method here which accepts a Predicate.. an in predicate in this case.

Can a JPA Query return results as a Java Map?

Returning a Map result using JPA Query getResultStream Since the JPA 2.2 version, you can use the getResultStream Query method to transform the List<Tuple> result into a Map<Integer, Integer>: Map<Integer, Integer> postCountByYearMap = entityManager.createQuery(“”” select YEAR(p.createdOn) as year, count(p) as postCount from Post p group by YEAR(p.createdOn) “””, Tuple.class) .getResultStream() .collect( Collectors.toMap( tuple -> ((Number) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)