Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenJPA不获取OneTONE关系_Jpa_Openjpa - Fatal编程技术网

OpenJPA不获取OneTONE关系

OpenJPA不获取OneTONE关系,jpa,openjpa,Jpa,Openjpa,我在使用OpenJPA 2.2.1时遇到以下问题: TypedQuery<OdpObjectScheduleEntity> q = em.createQuery( "SELECT s FROM OdpObjectScheduleEntity s WHERE s.updateFreq IS NOT NULL", OdpObjectScheduleEntity.class); List<OdpObjectScheduleEntity> result = q.g

我在使用OpenJPA 2.2.1时遇到以下问题:

TypedQuery<OdpObjectScheduleEntity> q = em.createQuery(
    "SELECT s FROM OdpObjectScheduleEntity s WHERE s.updateFreq IS NOT NULL",
    OdpObjectScheduleEntity.class);
List<OdpObjectScheduleEntity> result = q.getResultList();
但结果的元素看起来似乎是延迟获取对象,例如,OdpObjectScheduleEntity[object=OdpObjectEntity[id=23851,name=null,parent=null,odpClass=null],updateFreq=120]。我是否遗漏了一些明显的东西,或者这是OpenJPA中的一个bug?我可以通过做一些可怕的事情来解决这个问题,比如

for (OdpObjectScheduleEntity schedule : result) {
    // simply schedule.getObject() doesn't work
    schedule.getObject().toString();
}

是否有更好的方法强制加载关系?

我从未使用过OpenJPA,因此我无法告诉您到底是什么错误,但您可以尝试使用JOIN FETCH:

有关更多信息,请参见示例

for (OdpObjectScheduleEntity schedule : result) {
    // simply schedule.getObject() doesn't work
    schedule.getObject().toString();
}
TypedQuery<OdpObjectScheduleEntity> q = em.createQuery(
    "SELECT s FROM OdpObjectScheduleEntity s LEFT JOIN FETCH s.object WHERE s.updateFreq IS NOT NULL",
    OdpObjectScheduleEntity.class);
List<OdpObjectScheduleEntity> result = q.getResultList();