Now I want to retrieve a manager entity and also want to fectch the employee list eagerly. My query is like this:
But I am getting the following exception while firing the above query:
Exception in thread "main" javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: Employees of: bala.persistent.Manager [select m from bala.persistent.Manager m LEFT JOIN FETCH m.Employees where m.id=:mngid]
Can anybody explain why this exception and try to correct it. And one more doubt is that, how can I retrieve a list of employees for a given manager. I think of the following query but it is wrong.
But I am getting the following exception for the above query: Exception in thread "main" javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! [select e from bala.persistent.Employee e JOIN Manager m where m.id=:mngid]
Please explain the above two doubts. [ August 07, 2008: Message edited by: Christophe Verre ]
I understand that. But, look at the following sql query. I want to write in EJB QL.
And I have another problem. The Employee table is the database doesn't contain the manager id!!! following is my client code:
I know if I set emp.setManager(m) and emp1.setManager(m) would solve the problem. I don't want to do that. I want the JPA would automatically do that. What should I do in the entity class in order to achieve this.
I don't think you can. Concerning entity relationships, it is your responsability to set the necessary info in each entity. So you'll have to call setManager for each employee too.
2.1.7 Entity Relationships Note that it is the application that bears responsibility for maintaining the consistency of runtime relationships�for example, for insuring that the "one" and the "many" sides of a bidirectional relationship are consistent with one another when the application updates the relationship at runtime.
I guess, we can do it in Hibernate. I forgot how to do it. A wild guess is setting inverse=true on the Entity may be or else someting other than that. Anyway, If I find I would definitely post it. Thanks for you help!!!