我认为我不会完全理解fetch连接.
我有一个查询,我试图热切地"夸大"两个级别的引用.
也就是说,我A有一个可选Collection的Bs,每个B都有0或1 C.B已知该系列的尺寸很小(10-20顶).我想预取这张图.
A的B关系标记为FetchType.LAZY并且是可选的. B与...的关系C也是可选的FetchType.LAZY.
我希望我能做到:
SELECT a
FROM A a
LEFT JOIN FETCH a.bs // look, no alias; JPQL forbids it
LEFT JOIN a.bs b // "repeated" join necessary since you can't alias fetch joins
LEFT JOIN FETCH b.c // this doesn't seem to do anything
WHERE a.id = :id
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我看到确实已经获取了As B集合(我LEFT JOIN …
我有这个错误:
2020-11-16 22:36:09.313 ERROR 19428 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: collection was evicted; nested exception is org.hibernate.HibernateException: collection was evicted] with root cause
org.hibernate.HibernateException: collection was evicted
at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:43) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:102) ~[hibernate-core-5.4.22.Final.jar:5.4.22.Final]
Run Code Online (Sandbox Code Playgroud)
我创建一个 API REST 应用程序,我的实体具有以下组成:
public class Label {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long Id;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "label")
private Set<Release> releases;
Run Code Online (Sandbox Code Playgroud)
public class Release …Run Code Online (Sandbox Code Playgroud)