• +91 9723535972
  • info@interviewmaterial.com

Hibernate Interview Questions and Answers

Question - Query Criteria: Not Equal

Answer - import java.util.*; import org.hibernate.*; import org.hibernate.criterion.*; public class SimpleRetrieveTest { public static void main(String[] args) { HibernateUtil.setup("create table EVENTS ( uid int, name VARCHAR, start_Date date, duration int, location_id int);"); HibernateUtil.setup("create table locations ( uid int, name VARCHAR, address VARCHAR);"); // hibernate code start Session session = HibernateUtil.currentSession(); Transaction tx = session.beginTransaction(); Location location = new Location(); location.setName("USA"); location.setAddress("Address"); session.save(location); Event e= new Event(); e.setId(11111L); e.setName("testSave"); e.setStartDate(new Date()); e.setLocation(location); session.save(e); Criteria crit = session.createCriteria(Event.class); crit.add( Expression.ne( "name", "noName" ) ); crit.setMaxResults(1); List results = crit.list(); System.out.println(results.size()); tx.commit(); HibernateUtil.closeSession(); HibernateUtil.sessionFactory.close(); // hibernate code end } }   /////////////////////////////////////////////////////////////////////////   ///////////////////////////////////////////////////////////////////////// public class Location { private Long id; private String name; private String address; public Long ge

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners