Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

updating two tables

 
maganti suryanarayana
Ranch Hand
Posts: 53
Java MyEclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Select statements select things, they don't update things. Update statements update tables.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic