RevisionRepository return entity with different List implementation (PersistanceBag ->ListProxy)

231 views Asked by At
org.springframework.data.repository.history.RevisionRepository
Entity entity = repository.findLastChangeRevision(entity.getId()).get().getEntity();

return entity with list as ListProxy.

Normal CrudRepository

repository.findById(id)

return the same entity with identical content, but list with type PersistentBag.

This difference case problem with asserting this two object in integration tests.

Any solutions?

1

There are 1 answers

2
Jens Schauder On BEST ANSWER

Don't test for equality but for equality of content. How to do that depends on your testing and assertion library you use.

AssertJ for example has containsExactlyInAnyOrder and containsExactly for this.

Some vague background

Hibernate and in general all JPA implementations and most ORMs either replace/manipulate the byte code of your classes or use proxies or special implementations in order to do their job. One important part is dirty-tracking, i.e. JPA will notice when you change an entity, e.g. by adding an element into a collection. In order to do that they'll have to do some magic like replacing your list by some other class that notifies the JPA implementation of such actions.

For that reason you might find implementations from your JPA implementation in your entity instances.