This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes SQL-Query not returning specified Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "SQL-Query not returning specified Object" Watch "SQL-Query not returning specified Object" New topic

SQL-Query not returning specified Object

Saikiran Madhavan

Joined: May 15, 2006
Posts: 28
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:-


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
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

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

Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Saikiran Madhavan

Joined: May 15, 2006
Posts: 28
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 Madhavan

Joined: May 15, 2006
Posts: 28

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

thanks all

I agree. Here's the link:
subject: SQL-Query not returning specified Object
Similar Threads
Hibernate with native SQL issue
Error in named native query (Invalid Column Name)
CGLIB Exception
how to save collection object into database
Question on deletes