Issue Type: New Feature New Feature
Affects Versions: 4.1.7
Assignee: Unassigned
Components: core
Created: 12/Sep/12 2:40 PM
Description:

Scenario: one simple entity, no foreign keys, value fields only. InnoDB, or any db that implements row-level locking.

A hibernate transaction which gets a list of entities based on a query, list result in some order A, and changes all of them with bean setters.

A simultaneous transaction which gets a different, but intersecting (intersection cnt >= 2) list of these entities, list result in some completely different order B (random relative to A), and changes all of them with bean setters.

Hibernate then on completion of non-throwing transaction(s) will iterate the changed entities based on comparisons with their states when queried, and then does updates for each one.

Hibernate makes no attempt to ensure that the iteration order of the updates in both transactions is the same for the intersecting entities, consequently there will surely be database deadlock. This same problem extrapolates to more difficult scenarios involving multiple entity types, multiple queries, and the whole range of things the hibernate programmer might do with setters that introduce alot of randomness in the update iteration order of the competing transactions, unless hibernate does something profound with its iteration order sorting.

This issue should be made well known to developers.

But most importantly, a simple session.updateNow(non_transient_attached_bean) would give hibernate programmers the ability to take control of update orders when they need to solve deadlock issues.

Should not be too difficult. Just call the internal code that causes SQL inserts/updates right then and there, and update the current state of the entity at time of call into the cache where state is being saved for the purpose of determination if dirty on session completion.

Also, this call would have the same effect as query.executeUpdate(), which would mean that the programmer would have absolutely complete control over update orders to make deadlock in the database impossible.

Currently, it is impossible for the programmer to control order that sql update/insert happens other than with batch commands.

Environment: all
Project: Hibernate ORM
Priority: Major Major
Reporter: Andrew Nuss
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira