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} package models.specific;
import java.util.Set;
import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.ManyToMany;
import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode;
@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 |
|