Tag Archives: Hibernate

Customize order by in JPQL

Ref : http://stackoverflow.com/questions/9262413/hibernate-dynamic-order For example, if there is a customize ordering in enum or a specific field. We can use “Case when ? else ? end” syntax in order by. (Supported in JPA) SELECT o FROM Cat o ORDER BY CASE o.name WHEN ‘Tom’ THEN 0 ELSE 1 END

Hibernate lazy init collection

Using Hibernate.Initialize may experience an issue, the session is not yet initialize. Ref: http://blog.9mmedia.com/?p=272 Add these before that SessionFactory sf = ((HibernateEntityManagerFactory)entityManagerFactory).getSessionFactory(); Session session = SessionFactoryUtils.getSession(sf, false); SessionImpl source = (SessionImpl) session;   I was using EntityManagerFactory from JPATemplate instead for PersistantCollection check here SessionImplementor sessioni = (SessionImplementor) sessionf.openSession(); Session s = (Session) sessioni; for(Object coleccion:… Read More »