mazhar wrote:
Hi,
I had a similar problem where I wanted to query the DB and set a generated identifier (other than the primary key) in the interceptor. Yes, you are right that you can't start a new transaction. I think interceptor is the last possible artifact that Hibernate exposes before stuff is fired to the database. Anyway, you may however fire native SQL. This was my workaround.
https://forum.hibernate.org/viewtopic.php?f=1&t=995904I raised the query and also answered it :)
Hope this helps you.
Thanks, it works: I have executed a SQL query within onDelete method...
But now I have the next problem:
really, A entity I want to modify is related to B in this way: A -> B, this is, there is an association (unidirectional aggregation) between both entities, so I need to set null the A's foreign key (to B) just before delete B. And I must to do this in the same transaction. But if I set a.setB(null) (with a SQL query), this is not visible in the moment of delete B so I get a ConstraintViolationException.
How could I do that?