• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate with native SQL issue

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,
I've got an problem in hibernate with SQL, my code is as below -


It gives me following error -


could you please help me out in this regard.

Thanks in advance
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankur,

When you use 'select' in either an HQL or native SQL query, Hibernate does not return the object in your 'from' clause. Just as when using non-Hibernate SQL, 'select event.* ...' returns all the columns from the event table. The List you get back from your query is a list of Object[] (object arrays). Each element in the list is an array of Objects and each element in the array represents one column in the event table.

For example, if I have a table defined as:

that contains the following data:

and I use a Hibernate SQL query as follows:

I get a List of Object[]. The first element in the List represents the first row in my result set:

Object[0] is of type BigInteger and has a value of 1
Object[1] is of type String and has a value of "Madouros"

The second element in the List represents the second row in my result set:
Object[0] is of type BigInteger and has a value of 2
Object[1] is of type String and has a value of "Johnston"

etc.

Not seeing your tables, I cannot say exactly what you get back. But, this should give you the idea.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi David,

I too face the same issue as you told, i am using sql-query in my hbm and instead of getting my specified Mailbox Object, i am getting collection of Object.

Can you tell me how to write the same peice of SQL in HQL and to retrieve my specified Object

my hbm file is as below:-


the high-lighted query is the problematic one.
The associated Account.hbm is also given below



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
Saikiran,

Please don't duplicate post. You have already created a thread on this topic. Which is right here

https://coderanch.com/t/217667/ORM/java/SQL-Query-not-returning-specified

And answers both questions here, so I don't want to have to duplicate my answers to two different threads.

Good Luck

Mark
reply
    Bookmark Topic Watch Topic
  • New Topic