File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate - Native SQL & result set updates? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate - Native SQL & result set updates? " Watch "Hibernate - Native SQL & result set updates? " New topic
Author

Hibernate - Native SQL & result set updates?

Eric Martin
Greenhorn

Joined: Jul 15, 2005
Posts: 22
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 ;)


Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

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

Joined: Jul 15, 2005
Posts: 22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate - Native SQL & result set updates?
 
Similar Threads
Update JTable when SQL DB changes ?
Retrieving meta data / column name from a native sql query / store procedure
how can I update xml file in java?
batch update in SQL
Help me to Update only selected Fields and not all the columns in database through hibernate ??