在同一级别使用连接提取提示超过1次会导致异常(JPA,Eclipselink)

时间:2015-05-20 19:44:08

标签: java jpa eclipselink fetch

虽然此代码按预期工作

    TypedQuery<Subject> query = em.createQuery("select s from Subject s",   Subject.class);
    query.setHint(QueryHints.FETCH, "s.person");
    query.setHint(QueryHints.FETCH, "s.person.att");
    query.setHint(QueryHints.FETCH, "s.person.att.name");
    System.out.println(query.getResultList().size());

添加另一个提示以获取与&#34; name&#34;

相同级别的另一个属性
query.setHint(QueryHints.FETCH, "s.person.att.title");

引起奇怪的异常:

Exception [EclipseLink-6044] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.QueryException
Exception Description: The primary key read from the row [DatabaseRecord(
NAME.IDNAME => 1
NAME.NAME => null)] during the execution of the query was detected to be null.  Primary keys must not contain null.
Query: ReadObjectQuery(name="title" referenceClass=Title )
at org.eclipse.persistence.exceptions.QueryException.nullPrimaryKeyInBuildingObject(QueryException.java:928)
...

(无论使用哪种属性和顺序都无关紧要。)

0 个答案:

没有答案