aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Join Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Join Problem" Watch "Hibernate Join Problem" New topic
Author

Hibernate Join Problem

C Rakesh
Greenhorn

Joined: May 04, 2009
Posts: 18
Hi,

I have the following HQL(Join operation) which should return two objects of type RecruitmentManagerSchedule and RecruitmentManagerRequirement. The HQL should return two objects

try {
Query query = session.createQuery("select recMgrSch, recMrgReq from " +
"com.hrms.persistence.beans.RecruitmentManagerSchedule as recMgrSch, " +
"com.hrms.persistence.beans.RecruitmentManagerRequirement as recMrgReq " +
"where recMgrSch.requirementid = recMrgReq.requirementid and recMgrSch.statusid = :statusId");
query.setInteger("statusId", 31);
log.debug("Getting Query : " + query);
List remindersList = executeQuery(query, session);
log.debug("remindersList size : " + remindersList.size());
return remindersList;
}

the code above execute fine and prints "remindersList size : 3" in logs

I am iterating the remindersList and assigning the list values into an Object array.

while(reqIterator.hasNext()){
//since the list has two object types(RecruitmentManagerSchedule and RecruitmentManagerRequirement),
//assign the list to object array, and take the objects from the array
Object[] resultObj = {(Object[])reqIterator.next()};
RecruitmentManagerSchedule recMgrSch = (RecruitmentManagerSchedule)resultObj[0];
RecruitmentManagerRequirement recMgrReq = (RecruitmentManagerRequirement)resultObj[1];
}

Now I am expecting that I'll get RecruitmentManagerSchedule object from resultObj[0] and RecruitmentManagerRequirement object from resultObj[1]. But I am getting the exception
"Exception While listing the Reminders java.lang.ClassCastException: [Ljava.lang.Object;"

Also I am getting only one object in the array "resultObj" instead of two.
If I am slelecting only one object in the HQL (ie, select recMgrSch from .....) the above code works fine.

Please guide me

Thanks,
Rakesh


SCJP 5.0, Preparing for SCWCD
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

remember and use the code tags - makes it easier to read.

Also take out the curly braces from this line:


Sean


I love this place!
C Rakesh
Greenhorn

Joined: May 04, 2009
Posts: 18
Sean Clark wrote:

remember and use the code tags - makes it easier to read.

Also take out the curly braces from this line:

Sean


Hi Sean,

Thanks!!! that was the issue . Once again thanks a lot.
How to use code tags??

Warm Regards,
Rakesh
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

Glad that helped.

When writing the message there is a "Code" button at the top. Press and the code tags will appear and then you can just put in your code between the tags.

Sean
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate Join Problem