• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Delete validation in 'Pre Delete'

 
Sharon Adar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

In our application we have decided to add �erasion validation� � By using pre-delete, we catch all entities erasion requests, and check by querying the DB whether any applicative* references exist to the deleted entity
(* Applicative reference is a reference which can be seen in the java object, and won�t be automatically deleted once the requested entity is removed)

The problem is, that before we run the erasion validation � we make some applicative changes, and then querying the DB by using SQL statements. In this level, the application references are not synchronized with the DB references, and not all applicative changes are reflected in the DB.

One kind of solution will be Flush the DB before executing the validation queries. This solution is bad since we catch the delete at �pre delete� stage, and flushing during cascade (which may happen if we delete a hierarchy of objects) is wrong.

Any better ideas of how can I ensure the DB is synchronized with my java application?

Thanks in advance,
Sharon.
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sharon,

This is a difficult question to answer without specific examples. What cases are you worried about that can't be handled through appropriate cascade mappings?

I've found in practice it's far better to handle as much as possible through the hibernate layer to minimize these sorts of issues. I have seen cases where it takes quite a bit of finesse to delete a complex set of relationships, but it can be done with correct mappings and judicious flushing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic