• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Not getting managed Entity as query result

 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic