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 updating two tables Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "updating two tables" Watch "updating two tables" New topic
Author

updating two tables

maganti suryanarayana
Ranch Hand

Joined: Mar 30, 2010
Posts: 53

Hi all,

I want to update two tables using hibernate query which modifies a common column in both the tables. I would like to write the query in hibernate without using update statement. I want to use select statement which is equal to update statement.

Thanks & Regards
Surya


surya
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56150
    
  13

Select statements select things, they don't update things. Update statements update tables.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1282

You can write a select statement to select an entity. When you make changes to that entity the provider will detect that the entity is dirty (has been changed) and when the transaction commits the persistence provider will generate an update statement for you to update the table. But in the end whether you write it or it is generated by the persistence provider Bear is 100% correct it is an update statement that updates the table. I would recommend learning fundamentals first before tackling an ORM as some of this may be hidden from you and might seem confusing. If you are using hibernate you can configure it to output the SQL it generates which will help you to see what is actually happening.

The important take away is that the following statement is not correct.
I want to use select statement which is equal to update statement.


[How To Ask Questions][Read before you PM me]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: updating two tables
 
Similar Threads
Hibernate - Slow Query on Entity Superclass
How SELECT can produce deadlock?
Spring JDBC Vs Hibernate?
Hibernate: column function on insert/update
How to update multiple columns in Hibernate(using HQL query)?