Reputation: 20460
Suppose we have a User class, if I want to update it's name:
User user = User.findById(123); user.name = "someone"; user.save();
The generated SQL would be
update user as user0 set user0.name = ? user0.email = ? .....
That means Play
didn't realize I just want to update a single field. Is there any way could make the generated SQL only update the specified fields ?
Upvotes: 0
Views: 796
Reputation: 3833
You can use hibernate's dynamic update feature : http://www.mkyong.com/hibernate/hibernate-dynamic-update-attribute-example/
But remember that this have negative impact on performance as database cannot cache statements. See here for others explanations : Hibernate : dynamic-update dynamic-insert - Performance Effects
Upvotes: 0
Reputation: 55798
Info: this is answer for Play 2 + Ebean! so it DOES NOT work with Play 1 + JPA
There are some options in Ebean's API, so you should check it and choose one:
Update<T>
- check in the sample for @NamedUpdates
annotationEbean.createUpdate(beanType, updStatement)
SqlUpdate
- you can just perform raw SQL update, without need for giving the entity typeUpvotes: 1
Reputation: 73568
This is dependent on whether Play (or actually Avaje Ebean) actually tracks which of the fields are changed. It's simpler to update all of the fields instead.
This isn't an issue performance-wise either, so I wouldn't waste too much time looking for a solution.
Upvotes: 0