You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Adam Furmanczuk <af...@knowtrek.com> on 2013/01/31 18:18:48 UTC
Cannot join on constant field - more specific
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
need to be more specific here:
@OneToMany(mappedBy="stampOwner", cascade =
CascadeType.ALL,fetch=FetchType.LAZY)
@JoinTable(name="TEMPSTAMP",
joinColumns={
@JoinColumn(name="STAMPOWNER_DID", referencedColumnName="DID"),
@JoinColumn(name="TEMPSTAMP.TEMPTYPE", referencedColumnName="OUTGING")
})
private List<TempStamp> tempOutgoingList;
// similar other three lists but with other constant
[..]
> When device and its lists get persisted, all database entries are
> correct. Problem is with retrieving. Suppoose I have device with 4
> lists with n elements each different
values.
> When retrieving devices with a TypedQuery, I always end up, with 4
> elements in each list having all the same value.
I need to correct, I end up in every list with 4 * n elements.
so my whole JoinTable annotation has no effect.
As to my issue with merge():
List<Device> runtimeList;
// I retrieve its objects with:
TypedQuery<Device> dQuery = em.createQuery("select d from Device d",
Device.class);
when running merge/persitance I iterate over that list and use:
EntityTransaction tx = em.getTransaction();
tx.begin();
for(Device dSaved : runtimeList){
Device dfound = em.find(WRG.class, savedDevice.getId());
if (dfound != null) {
dSaved = em.merge(dfound);
} else {
em.persist(dSaved);
}
}
tx.commit();
> Now, when I would run em.merge(dSaved) instead of em.merge(dFound)
> I get the Error:
> "An object of type <X> with oid <Y> already exists in this context
> another cannot be persisted"
Merging the Object I just found causes no error, but I never get new
values, as all changes are loaded from databases and current discarded.
Thanks for help, greetings,
Adam
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAlEKp3gACgkQefEEI87R1DfjjACfYFd6Tn/JmUnI8lPllEBtzWQD
vCgAnjg2mSgtsJpiyr33KAhBUybahnR3
=CKRj
-----END PGP SIGNATURE-----