oracle - How can I handle/recover a DB Integrity constraint violation exceptions in hibernate? -


i'm developing big web application uses jsf , hibernate orm. hibernate sessions long (the user can big amount of modifications on screen , changes persistent on db when he'll press save button) i'm struggling issue of roll-back / cancellation of user modification , looking different solutions , approaches.

i want recover violation constraint exception ("ora-02292: integrity constraint").

consider following scenario:
there table 'x' record 'x' , table 'y' record 'y' - 'x' depends on 'y' foreign key. user trying delete record 'y' , although there future possible integrity constraint violation on step, i'm not throwing exception because user able fix later , if won't fix , try save screen db throw exception aggregated user interface.

i can't find way recover violation.
in save process, after trying delete record 'y', db launches "ora-02292: integrity constraint" exception expected.
problem if such error occurred , user did fixed foreign key constraint selecting record instead of 'y', hibernate won't recognize because afaik still first try remove 'y' (because of action queue) , fail before comes action replaces 'y' entity.
what's going on db keeps firing exceptions while trying save changes , can't find way fix without refreshing entire screen (which means new hibernate session loosing of user new data). seems action queue saves delete action , won't clear if session "evict" or "clear" methods called.

i aware validate changes before committing them , might work i'm not interested in kind of solution because: 1. validate large amount of possible changes can cause performance issue, furthermore believe oracle db can me better. 2. don't want enforce user specific order of actions.


update:

i feel should shed light on application requirements:
application built in way committing changes db can occur @ save phase - this user demand , unfortunately it's not open discussion,
idea behind user wants make changes without specific kind of order , fix wrong set of data whenever wants before pressing save button.
result of requirement, validation preferred take place in save phase.
aware of possibility of validating each 1 of user modification right away dragan bozanovic pointed out bellow, said not preferred way user.

so, see can solve problem in 3 different ways:
1. validate modifications in save phase - said can performance issue because there can many validations make.
2. validate each user modification right away - again not preferred option user if must.
3. find way of handling such scenarios (of integrity constraint...) in db level - i`ll appreciate more suggestions, if any, approach.

you can't, transaction marked rollback, fail without repeated deletion.

the solution validate data/actions before execute them in db.

but said don't want it.

"validate large amount of possible changes can cause performance issue" not validating them can cause inconsistent , wrong saved state (if have validation constraints difficult/impossible implement in database).

"oracle db can me better" disagree. other foreign key, not null , few other constraints, java based validation more flexible , powerful.

"i don't want enforce user specific order of actions." want allow them delete should not deleted , raise error 10 minutes later when try save cumulative changes may dependent on each other (and assume deletion successful). sure user appreciate error right after try perform deletion, in order not loose 10 minutes more in vain.

my point , suggestion should validation before instruct hibernate delete entity.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -