OpenJPA不获取OneTONE关系
我在使用OpenJPA 2.2.1时遇到以下问题: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
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();