I am using hibernate 3 annotations to annotate relationship between classes.
I have a class with name Person and below is the content
Class Person { Private Contact a; Private Department b; private String name;
@OneToOne(fetch=FetchType.LAZY, mappedBy="Person", cascade=CascadeType.ALL) public Contact getA() { return a; }
@OneToOne(fetch=FetchType.LAZY, mappedBy="Person", cascade=CascadeType.ALL) public Contact getB() { return b; } }
I am using below statements to retrive person details like Contacts and Department which he belongs
DetachedCriteria searchCriteria = DetachedCriteria.forClass(Person.class) .add(Restrictions.eq("name", "John")) .addOrder(Order.asc("name")); getHibernateTemplate().findByCriteria(searchCriteria);
But in this same even when i want only contact details and not Department, it is fetching data from both the table. I need to know how to add a filter or restriction in such a way only contact details are fetched and Department related details are not even queried.
|