Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not getting managed Entity as query result

 
vikasids sharma
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I have a table structure like
Organisation (has userId as FK from OwnerDetail)
OwnerDetails (Organisation id as FK)


I want to fetch an organisation along with the owner by using hibernate . The situation is like i want to retrieve few attributes from Organisation and few from OwnerDetails .
I am using query.uniqueResultset() which returns me an Object but i expect it to be my Entity (Organisation).

When i try to type cast returned Object to Organisation , i m getting ClassCast Exception.

Please let me know how can i get back my Entity with only selected attributes populated.


Thanks
Vikasids
 
Pallu Sagar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please chk your table relationship..seems to be strange for me..nyways...

If your query has select clause then you cant get 'Organisation' object resultset... query would return you a resultset...
Then you have to write your own QueryResutSet mapper for mapping / binding...

Simple way to do is remove select clause and identify your fetching strategies...and apply those on collection
 
vikasids sharma
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pallu Sagar wrote:Please chk your table relationship..seems to be strange for me..nyways...

About relationship , the system is like user cannot exist without organisation....

If your query has select clause then you cant get 'Organisation' object resultset... query would return you a resultset...
Then you have to write your own QueryResutSet mapper for mapping / binding...

Sorry , i did nt understand that i cannot get my Entity Object by using SELECT clause .
Can you please provide me example where we fetch selected attributes from two related tables and getting back an Entity as result of uniqueResultset?

Simple way to do is remove select clause and identify your fetching strategies...and apply those on collection
 
Pallu Sagar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i mean to say if you have "Select o.name, o.address from organisation o" in this kind of query you will not get you entity in resultset..it would be pure resultset .

If query is "Select o.* from Organisation o" in this case you will get your entity in resultset.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic