HQL left join of un-related entities

Currently, the theta-style on joining the unrelated classes in the where clause using HQL only supports inner join. The request for supporting the outer join for such situation is currently the 3-rd most voted enhancement but I don’t think this feature will be implemented in the near feature as it requires the re-implementation of the … Read more

HQL Hibernate INNER JOIN

Joins can only be used when there is an association between entities. Your Employee entity should not have a field named id_team, of type int, mapped to a column. It should have a ManyToOne association with the Team entity, mapped as a JoinColumn: @ManyToOne @JoinColumn(name=”ID_TEAM”) private Team team; Then, the following query will work flawlessly: … Read more

IN-clause in HQL or Java Persistence Query Language

Are you using Hibernate’s Query object, or JPA? For JPA, it should work fine: String jpql = “from A where name in (:names)”; Query q = em.createQuery(jpql); q.setParameter(“names”, l); For Hibernate’s, you’ll need to use the setParameterList: String hql = “from A where name in (:names)”; Query q = s.createQuery(hql); q.setParameterList(“names”, l);

How to escape reserved words in Hibernate’s HQL

You could achieve it by a workaround using your custom “alias to map” transformer, so your code would change to something like this Query q = mySession.createQuery( “SELECT u.id AS id, u.name AS text, u AS obj FROM User u”) .setResultTransformer( AliasToMapTransformer.renameAlias(“obj”, “object”).build() ); And then using this class: public class AliasToMapTransformer extends BasicTransformerAdapter { … Read more