Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Hibernate - Native SQL & result set updates?

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be more of a MySql question, but thought I'd start here.

I am retrieving a result set from a MySQL table using Hibernate's native sql createSQLQuery(sql) method. I want to be able to make updates on the data, but won't be guaranteed that I have a unique identifier to use for an update statement. So, I was wondering if there is a way to say that I want to update X row number of a particular result set?

I have some other options, but thought I'd find out if there is already a way to do something similar. Hibernate's site is down, or else I'd ask there ;)


 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, any time you're updating a row, you need a primary key. So, that ResultSet should contain some primary key.

If the primary key maps to a key for a Hibernate managed POJO, you could just load that POJO with the primary key, update the POJO, and let Hibernate take care of the rest. That way you get the benefit of extraction through your SQL query, and persistence through the Hibernate framework!

-Cameron McKenzie
 
Eric Martin
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cameron. Since I'm using the Native SQL, I don't have any other object associated with the results. I think I'm going to have to manually add a PK to the data or enforce that the data already includes one.

Thanks again.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic