When a collection is defined on a mappedsuperclass:
{code:java} @MappedSuperclass public abstract class RelatedToEvents extends Base { protected Set<Event> events = new LinkedHashSet<>();
public void setEvents(Set<Event> events) { this.events = events; } } {code}
extended by
{code:java} @Entity @Inheritance(strategy = InheritanceType.JOINED) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class RequestWithEagerEvents extends RelatedToEvents {
@ManyToMany(fetch = FetchType.EAGER) @Fetch(FetchMode.SELECT) public Set<Event> getEvents() { return events; }
} {code}
and {code:java} @Entity @Inheritance(strategy = InheritanceType.JOINED) @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class RequestWithLazyEvents extends RelatedToEvents {
@ManyToMany(fetch = FetchType.LAZY) @Fetch(FetchMode.SELECT) public Set<Event> getEvents() { return events; }
} {code}
Accessing the collection lazily after getting the entity from database returns no results, but results when loaded eagerly. When the collection property is moved outside the @MappedSuperclass or without bytecode enhancement, everything works.
Test case: https://github.com/nikowitt/hibernate-test-case-templates/tree/HHH- 12061 12601-eager-lazy-mappedsuperclass-collection |
|