Reputation: 183
My SQL query is
select * from PTAX_ECHALLAN_DATA where IDENTIFICATION_NO in('ECC0013056','192009028150','20150086699');
How it write using hibernate? If it possible with hql or criteria?
Upvotes: 1
Views: 397
Reputation: 923
You can use hibernate criteria interface for mysql in() function.In Hibernate, the Criteria API helps us build criteria query objects dynamically. Criteria is a another technique of data retrieval apart from HQL and native SQL queries. The primary advantage of the Criteria API is that it is intuitively designed to manipulate data without using any hard-coded SQL statements. Programmatic behavior offers compile-time syntax checking; as a result, most error messages are delivered during compilation.
You can try this one, I tested and it is working as expected.
Criteria crit = this.sf.getCurrentSession().createCriteria(PTAX_ECHALLAN_DATA .class);
Criterion list = Restrictions.in("IDENTIFICATION_NO ", Arrays.asList(ECC0013056,192009028150,20150086699));
crit.add(list);
List<PTAX_ECHALLAN_DATA > results = crit.list();
System.out.println(" o/p details are :: " + results );
Upvotes: 2