How to get valued query from Hibernate Criteria(Not Logger)?
As per my knowledge there is no library available that allows you get Criteria query with its real values. So I came up with solution that allows you to do that.
Hibernate Assist, Its an open source Hibernate Criteria analysis tool. It has many features one of them is to get Criteria query with its value.
Download Library: www.javaquery.com/p/hibernateassist.html
Source Code
Criteria criteria = objSession.createCriteria(User.class); criteria.createAlias("Messages", "Messages"); criteria.createAlias("CreditCard", "CreditCard"); criteria.add(Restrictions.eq("Email", "vicky.thakor@javaquery.com")); List<User> listUser = criteria.list(); HibernateAssist objHibernateAssist = new HibernateAssist(objSession); objHibernateAssist.setCriteria(criteria); String strQuery = objHibernateAssist.getValuedCriteriaQuery(); System.out.println(strQuery);
Output
SELECT this_.id AS id0_2_, this_.username AS username0_2_, this_.password AS password0_2_, this_.email AS email0_2_, messages1_.id AS id1_0_, messages1_.user_id AS user2_1_0_, messages1_.message_text AS message3_1_0_, creditcard2_.id AS id2_1_, creditcard2_.user_id AS user2_2_1_, creditcard2_.credit_card_number AS credit3_2_1_ FROM user_master this_ INNER JOIN message messages1_ ON this_.id = messages1_.user_id INNER JOIN creditcard creditcard2_ ON this_.id = creditcard2_.user_id WHERE this_.email = 'vicky.thakor@javaquery.com'Note: I tried to manage almost all cases however if you find for your Criteria its not working please comment your issues.
0 comments :