This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Updating an entity object without loading the same Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Updating an entity object without loading the same" Watch "Updating an entity object without loading the same" New topic
Author

Updating an entity object without loading the same

Keerthi Kumar Narayan
Greenhorn

Joined: Feb 01, 2013
Posts: 4
Dear All,

Im quite new to JPA. I have a requirement where i need to create a plan and update whenever required. In the current implementation, to update a plan, that plan will be reloaded first and then set or update to the required values and persist it. So, is there any way in JPA to update the plan directly without loading it from the database?

Thanks in advance.

Regards,
Keerthi Kumar N
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
Reading the object, then updating it is normally the best way to update an object, and ensure correct versioning/locking, caching and consistency.

You can also issue a direct update in JPQL using an UPDATE query,

See, http://en.wikibooks.org/wiki/Java_Persistence/Querying#Update_and_Delete_Queries


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Keerthi Kumar Narayan
Greenhorn

Joined: Feb 01, 2013
Posts: 4
But, here the problem is that i need to update not a single entity. Need to update hierarchy of entities.. Any idea how to achieve this?
 
Consider Paul's rocket mass heater.
 
subject: Updating an entity object without loading the same
 
Similar Threads
difference between modifying a persistent entity within a transaction and outside a transaction
Strategies for handling updates in existing JPA persistence classes
JPA problem!
JPA and DAO
Using CMP & JPA in same application