| When a collection is defined on a mappedsuperclass:
@MappedSuperclass
public abstract class RelatedToEvents extends Base {
protected Set<Event> events = new LinkedHashSet<>();
public void setEvents(Set<Event> events) {
this.events = events;
}
}
extended by
@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;
}
}
and
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;
}
}
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. |