aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Exception while firing the join queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Exception while firing the join queries" Watch "Exception while firing the join queries" New topic
Author

Exception while firing the join queries

krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
Hi,
I have the following two Entities.
Manager:

Employee:

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 ]

Thanks&Regards, Krishna.
SCJP1.4, SCWCD1.4, SCBCD 5.0
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16


You'd better follow the bean naming convention and rename it "private List employees;"


[My Blog]
All roads lead to JavaRanch
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
Hi Christophe,
Thanks!!! First problem was solved.
Could explain about my second doubt.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Do you need a JOIN ?
select e from bala.persistent.Employee e WHERE e.manager.id = :mngid
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
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.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

The Employee table is the database doesn't contain the manager id!!!

Why ? The owning side of the relation is Employee, isn't it ? If MANAGER_ID is not in the employee table, where is it ?
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
I mean to say that the JPA is not inserting the manager id in the employee table. The employee table contains the column 'Manager_id' but it doesn't contain any value.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.
krishna bulusu
Ranch Hand

Joined: Aug 28, 2006
Posts: 185
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!!!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Probably this, but that's Hibernate, not JPA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception while firing the join queries