• 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

Problem with named queries

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am trying to use a named query but cannot get it to work.

The mapping element is:


I am calling it like this:



The pertinent section of the log looks like this:



Any ideas?

Thanks,

Howard
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your log above, the query is referenced as "events.TsnEvent.findEventsByGroup".

Try using the full name:

Query q = session.getNamedQuery("events.TsnEvent.findEventsByGroup").setInteger("id", new Integer(1100));
 
Howard Ralston
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Scott,

I tried that and also changed the variable "id" to match "groupId" and used the alias "r". Now I get a different error. It looks as though Hibernate is trying to run the query but generates an exception. The relevant error seems to be: "ResultSet can not re-read row data for column 3." See below.

Mapping:



Code:



Error:

 
Howard Ralston
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I turned on more debugging and found the following. It looks as though Hibernate is pulling 1 record, closing the statment and resultset and then trying to read it again. Is that the case? If so, why? Shouldn't it bring back the full 27 records and then iterate through them?

Here is the new log:

 
Howard Ralston
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I figured it out.

SQL Server requires that you read the columns sequentially into your resultset. I had changed the mapping around and the get() statements were no longer sequential. If you use a tool such as Hibernate Synchronizer (like I did to create your java files, make sure that you keep the property elements in the same order.

If your columns are retrieved in the order:
1. id
2. myname
3. mydate
4. mycity

Your get statements must retrieve in the same order:
1. getId()
2. getMyname()
3. getMydate()
4. getMycity()

If not you will the the error I had.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good find !
 
Look ma! I'm selling my stuff!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic