I am moving some code from the old version of OpenJPA to a newer one, in particular to
OpenJPA 2.1.0-SNAPSHOTversion id: OpenJPA-2.1.0-SNAPSHOT-r422266: 990238
My previous working request failed in this new environment (details that a crash later occurred), but reworked the request, which worked fine. The difference is on which side of the one-to-many query I start. My question has two parts:
- Is there a “right” side with which to start such a request? Do we expect both requests to work?
- If we expect both to work, can we explain the failure that I see.
For brevity, the classes are pretty shortened here. One side of the relationship:
@Entity
@Table(name="CWS_MDS")
public class CwsMd implements Serializable {
@Id
Column(name="RSM_ID", unique=true, nullable=false, length=128)
private String rsmId;
@OneToMany(mappedBy="cwsMd")
private Set<CwsPubOperationRef> cwsPubOperationRefs;
}
other side
@Entity
@Table(name="CWS_PUB_OPERATION_REF")
public class CwsPubOperationRef implements Serializable {
@EmbeddedId
private CwsPubOperationRefPK id;
@ManyToOne
@JoinColumn(name="RSM_ID", nullable=false, insertable=false, updatable=false)
private CwsMd cwsMd;
}
A query that works:
<named-query name="good"> <query>
SELECT opref FROM CwsPubOperationRef opref
JOIN opref.cwsMd rsm
WHERE rsm.rsmId = :rsmId
</query>
</named-query>
,
<named-query name="bad"> <query>
SELECT opref FROM CwsMd rsm
JOIN rsm.cwsPubOperationRefs opref
WHERE rsm.rsmId = :rsmId
</query> </named-query>
, ,
org.apache.openjpa.persistence.PersistenceException: [jcc][t4][10120][10898][3.57.82]
Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null
WebSphere 8.0 Windows, DB2 .