[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Strange persistence layer behaviour
|
Hello,
A common problem when using a bidirectional relationship is setting one
side of the relationship but not the other. This problem will occur if
your application is setting the
LetterOfCreditGoederenOmsRegel.goederenOms but not adding the
LetterOfCreditGoederenOmsRegel to the LetterOfCreditGoederenOms's
collection of LetterOfCreditGoederenOmsRegel. Because the provider uses
a cache, the LetterOfCreditGoederenOms returned from the find does not
have its collection set until it is refreshed from the database
Both sides of the relationship need to be set as JPA does not provide
relationship maintenance to keep the cache insynch with what is in the
database.
Best Regards,
Chris
Willem Kunkels wrote:
Hi all,
I have come across something that I do not quite understand, maybe
someone can shed a light...
Here is the situation:
The entity LetterOfCreditGoederenOms contains lines wich can be
retrieved through the following mapping:
@OneToMany(cascade=CascadeType./REFRESH/, mappedBy =
"goederenOms", fetch = FetchType./LAZY/)
*private* Collection<LetterOfCreditGoederenOmsRegel> regels;
*public* Collection<LetterOfCreditGoederenOmsRegel> getRegels() {
*return* regels;
}
I have a bean that contains logic to compare two objects and determine
changes between the two. In one case I check whether I need to remove
something from the database. If so, I do the following:
omschrijving =
getEm().find(LetterOfCreditGoederenOms.*class*,
*new*
LetterOfCreditGoederenOmsPK(omschrijving.getVolgnummerInkooporder(),
omschrijving.getInkoopOrderNr(),
omschrijving.getInkoopOrderRegelNummer()));
getRemovedObjects().add(omschrijving);
getRemovedObjects().addAll(omschrijving.getRegels());
What I would expect (now that the LetterOfCreditGoederenOms object
'omschrijving' is managed) is that the call to getRegels() will get me
the lines associated with the omschrijving object. It does not do this.
What I need to do to get this working is adding the following just
after the find:
// A little note:
// You would expect that the regels can be
retrieved by
// calling the getRegels() method. For some
reason unknown,
// the persistence layer does not do this. The
only way
// to get the regels is a refresh of the
object we just
// found: cascading refresh then does get the
regels...
// weird...
getEm().refresh(omschrijving);
Anyone's got an answer to this enigma?
Cheers,
Willem Kunkels
Java Developer
Koopman International BV
Distelweg 88
1031 HH Amsterdam
The Netherlands
Tel.: +31 20 494 7 893
www.koopmanint.com
------------------------------------------------------------------------
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users