Hi Matt, Thanks so much for the reply. I tried with HQL but it is not returning correct result. Actually Employee is associated to Manager through Subordinate. (It is indirect association)
Get all employees with the given manager. May I know how the HQL query looks for this one. Thanks mraible wrote: > > I was never able to get QBE to work with the User object (which has an > association with Role), so I don't have a solution for you. I'd > suggest using HQL. > > Matt > > On 10/9/07, Lucky123 <[EMAIL PROTECTED]> wrote: >> >> >> Can anybody please help.. >> >> Thanks >> >> >> Lucky123 wrote: >> > >> > Hi Nathan, >> > >> > Thank you so much for the reply. >> > >> > public Employee() extends Subordinate{ >> > >> > private String employeeName; >> > public void setEmployeeName(String employeeName){ >> > this.employeeName = employeeName; >> > } >> > public void getEmployeeName(){ >> > return this.employeeName; >> > } >> > } >> > >> > public Manager(){ >> > >> > private String managerName; >> > public void setManagerName(String managerName){ >> > this.managerName = managerName; >> > } >> > >> > public String getManagerName(){ >> > return this.managerName; >> > } >> > >> > >> > private List<Subordinate> subordinates; >> > public void setSubordinates (List subordinates){ >> > this.subordinates = subordinates; >> > } >> > >> > public void getSubordinates (){ >> > return this.subordinates; >> > } >> > >> > } >> > >> > public Subordinate(){ >> > >> > private String subordinateName; >> > public void setSubordinateName(String subordinateName){ >> > this.subordinateName= subordinateName; >> > } >> > >> > public String getSubordinateName(){ >> > return this.subordinateName; >> > } >> > >> > >> > private Manager manager; >> > public void setManager(Manager manager){ >> > this.manager = manager; >> > } >> > >> > public void getManager(){ >> > return this.manager; >> > } >> > >> > } >> > >> > I'm trying to achieve: Get all employees with the given manager. Hope >> you >> > understand. I think in the previous post I have represented it >> > incorreclty. Sorry. >> > >> > >> > >> > Employee employee = new Employee(); >> > employee.setEmployeeName("ABC"); >> > employee.setManager(manager); >> > >> > Criteria criteria = session.createCriteria(Employee.class). >> > add(Example.create(employee ).excludeZeroes()); >> > >> > if(employee .getManager() != null) >> > { >> > criteria.createCriteria("manager").add( >> > Example.create(employee .getManager()).excludeZeroes()); >> > >> > } >> > >> > >> > >> > I have read that in Hibernate Query By Example ignores "Associations" >> are >> > ignored in such case will this work. Could you please help me. Is there >> > any way to solve this issue. >> > >> > >> > Thanks. >> > >> > >> > >> > >> > >> > >> > >> > melinate wrote: >> >> >> >> I think you might need to provide some more information for someone to >> >> help with this. Could you share your POJO's so we can see how you >> built >> >> the relationships betwen Manager and Employees. Are you trying to >> >> retrieve one Manager and a List of Employees? If the relationships >> are >> >> set up correctly it should just be a matter of fetching the Manager by >> id >> >> and the List of Employees will come with it [however you may have to >> read >> >> the list to avoid lazy loading issues]. >> >> >> >> HTH, >> >> Nathan >> >> >> >> >> >> ----- Original Message ----- >> >> From: "Lucky123" <[EMAIL PROTECTED]> >> >> To: users@appfuse.dev.java.net >> >> Sent: Thursday, October 4, 2007 2:13:00 PM (GMT-0800) >> America/Los_Angeles >> >> Subject: Re: [appfuse-user] Hibernate Example.create >> >> >> >> >> >> I have two entities stored in seperate database tables >> >> >> >> - Employee >> >> - Manager >> >> >> >> Every Employee has a Manager(or vice versa: Every Manager has several >> >> Employees) >> >> >> >> Get Manager with his employees. >> >> >> >> I tried Hibernate Query by example, but it is not returning anything.. >> >> >> >> Criteria criteria = session.createCriteria(Manager.class). >> >> add(Example.create(manager).excludeZeroes()); >> >> >> >> if(manager.getEmployee() != null) >> >> { >> >> criteria.createCriteria("employee").add( >> >> Example.create(manager.getEmployee()).excludeZeroes()); >> >> >> >> } >> >> >> >> Can anybody help. >> >> >> >> Thanks >> >> -- >> >> View this message in context: >> >> >> http://www.nabble.com/Hibernate-Example.create-tf1278198s2369.html#a13048884 >> >> Sent from the AppFuse - User mailing list archive at Nabble.com. >> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> >> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> >> >> >> >> >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/Hibernate-Example.create-tf1278198s2369.html#a13119569 >> Sent from the AppFuse - User mailing list archive at Nabble.com. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > > -- > http://raibledesigns.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- View this message in context: http://www.nabble.com/Hibernate-Example.create-tf1278198s2369.html#a13122601 Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]