M
M
MaxLich2019-02-13 15:53:13
Java
MaxLich, 2019-02-13 15:53:13

Why doesn't the @PreRemove annotation work for me?

I write integration tests for services with an in-memory base ( h2). Services do not contain any logic and simply call similar methods from the DAO. Services also have annotations @Transactional(at the class level). Methods for reading in services are annotated with @Transactional(readOnly = true). Now I'm testing a service for working with a directory. The directory entity itself is marked with annotations: @Entity, @Immutable, @EntityListeners(PreventAnyUpdate.class).

public class PreventAnyUpdate {
    @PrePersist
    void onPrePersist(Object o) {
        throw new RuntimeException("Can't create Entity!");
    }

    @PreRemove
    void onPreRemove(Object o) {
        throw new RuntimeException("Can't delete Entity");
    }
}

All tests pass, except for tests for delete(). Should throw an exception, but does not throw, but deletes everything normally (which it should not do at all). What's wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question