babanin
babanin

Reputation: 3584

Get updated entities by JPQL UPDATE query

We can track updated entities using @PostUpdate:

@Entity
public class Author {

    ...

    @PostUpdate
    public void postUpdate() {
        Tracker.trackEntity(this);
    }
}

When we update entity using EntityManager.merge(...) then postUpdate() will be invoked.

But how I can track entities modified using bulk update (EntityManager.createQuery(...).executeUpdate())?

Upvotes: 0

Views: 525

Answers (1)

user3973283
user3973283

Reputation:

You can't, unless you first do a query of the entities affected by that UPDATE query. That is the point of an UPDATE query, it goes straight to the DB and doesn't have hooks for such things as callbacks, or cascading.

Upvotes: 2

Related Questions