This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Configuration cfg = new Configuration();
cfg = cfg.configure();
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = cfg.buildSessionFactory();
Hibernate: select contact0_.ID as ID0_, contact0_.FIRSTNAME as FIRSTNAME0_0_, contact0_.LASTNAME as LASTNAME0_0_, contact0_.EMAIL as EMAIL0_0_ from CONTACT contact0_ where contact0_.ID=?
I am expecting the record with "Deepak" not to come as my filter coniditon is firstname='SATISH'. Can anybody help. I see the sql doesn't also have the filter condition clause.
Joined: Apr 17, 2011
I got the problem solved.
The problem was that Filter doesn't work if you are fetching using id value. I change the call from session.get to use Query interface and it is working.
Here is the changed code
Filter filter = session.enableFilter("limitByLastName");
Transaction tx = session.beginTransaction();
Query query = session.createQuery("from roseindia.tutorial.hibernate.Contact");
List list = query.list();
Iterator it = list.iterator();
Contact name = (Contact) it.next();
System.out.println("name :" + name.getFirstName());
Hibernate: select contact0_.ID as ID, contact0_.FIRSTNAME as FIRSTNAME0_, contact0_.LASTNAME as LASTNAME0_, contact0_.EMAIL as EMAIL0_ from CONTACT contact0_ where ? ='SATISH'
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com