• 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
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

SQL-Query not returning specified Object

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am using Hibernate 3.1 with SQL Server 2005,the problem i am facing is this.I have written a SQL-Query within my hbm file for returning a specified Object, that query is a complicated sub-query involving 3 tables.

first of all i am new to Hiberbate so i dont know how to convert the same query into HQL.

My SQL query is as below:-



The hbm files are as given below:-



Account.hbm



can anyone help me out why my query is not returning Mailbox object(s)and how to write the query in HQL format ?

thanks in advance
saikiran
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just quickly looking at the sql-query, in the mapping you don't tell Hibernate what kind of object it is supposed to return, so how is Hibernate going to guess? So Hibernate will be returning a list of Object arrays. so List<Object[]>.

Here are some ways to get Hibernate to return an List of your objects rather than a list of Objects arrays

sess.createSQLQuery("SELECT ID, NAME, BIRTHDATE FROM CATS").addEntity(Cat.class);

And in your case to tell Hibernate what types of Objects you want you can do something like this from the Hibernate documentation

 
Saikiran Madhavan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

I am sorry for posting the question multiple times.That question has got similar problem like that of mine, thats why i posted it there also.

Thank you for your reply and i will try this piece of code in my program.

Saikiran
 
Saikiran Madhavan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i got the desired object by adding the return tag...Thank you for your valuable advice.


thanks all

saikiran
 
There's a way to do it better - find it. -Edison. A better tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic