Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Strange persistence layer behaviour


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

Back to the top