users@glassfish.java.net

Re: _at_many-to-one with composite key for multiple columns challenge..

From: <glassfish_at_javadesktop.org>
Date: Sat, 21 Apr 2007 02:26:00 PDT

Thanks for the responses.

Marcus: The solution you provided is an alternative but it's not something we'd
like to do at this point.

mf125085: I didn't quite understand what you meant by "Meaning that updating one relationship could possibly
modify another relationship mapped to the same column".

Both relating columns are different (physically as well as in the entity definition) only common thing is the VPD_ID in the relationship.
so if I update the first one based on its value + vpdid I don't see why it will confuse with the
second column. It would have been all fine if I had a single-column PK on the other table.

But anyways I would like to discuss this situation a bit more because after
working on it for a while I have a feeling that it might be a bug
(I may be wrong though) in Toplink (no sure about Hibernate). I couldn't
find anything in the JPA Final Spec stating that this is not allowed, or maybe I don't know what I am looking for. I even went
thru Gavin King's book on JP with Hib and it's not mentioned there as well.

Here is a detail analyses to prove my claim about the bug:

1. The cut down version of the TestEntity

    //This will make sure that Toplink includes the VPD_ID in the INSERT Statement
    @Column(name="VPD_ID")
    public Long getVpdId() {
    return itemCategory.getVpdId();
    }

    @ManyToOne
    @JoinColumns( {
        @JoinColumn(name="SPEC_SETUP_TYPE01", referencedColumnName="SETUP_TYPE")
        , @JoinColumn(name="VPD_ID", referencedColumnName="VPD_ID", insertable=false, updatable=false)
    } )
    public SetupTypeEntity getSpecSetupType1()
    {
    .......
    }

    @ManyToOne
    @JoinColumns( {
        @JoinColumn(name="SPEC_SETUP_TYPE02", referencedColumnName="SETUP_TYPE")
        , @JoinColumn(name="VPD_ID", referencedColumnName="VPD_ID", insertable=false, updatable=false)
    } )
    public SetupTypeEntity getSpecSetupType2()
    {
    .......
    }


- In this state there is no complaint from Toplink and the it inserts a new record. But if we
pass any one or both SpecSetupTypes then there values don't get inserted.

2. Here is another cut down version of the TestEntity

    //This will make sure that Toplink doesn't include the VPD_ID in the INSERT Statement using this annotation
    @Column(name="VPD_ID", insertable=false, updatable=false)
    public Long getVpdId() {
    return itemCategory.getVpdId();
    }

    //Notice that VPD_ID doesn't have insertable=false.... and toplink uses this
//annotation to place the VPD_ID into the insert statement.
    @ManyToOne
    @JoinColumns( {
        @JoinColumn(name="SPEC_SETUP_TYPE01", referencedColumnName="SETUP_TYPE")
        , @JoinColumn(name="VPD_ID", referencedColumnName="VPD_ID")
    } )
    public SetupTypeEntity getSpecSetupType1()
    {
    .......
    }

    @ManyToOne
    @JoinColumns( {
        @JoinColumn(name="SPEC_SETUP_TYPE02", referencedColumnName="SETUP_TYPE")
        , @JoinColumn(name="VPD_ID", referencedColumnName="VPD_ID", insertable=false, updatable=false)
    } )
    public SetupTypeEntity getSpecSetupType2()
    {
    .......
    }


- In this state also it inserts a new record without any problem. It also
inserts the value for the SpecSetupType01. In the generated Insert statement VPD_ID is adjacent to the SPEC_SETUP_TYPE01 which
made me thinking that Toplink is generating the insert statements based on the annotations.

And this is why I feel that Toplink has this bug because in the first case it should have just included
the SPEC_SETUP_TYPE01 and SPEC_SETUP_TYPE02 columns in the insert statement because they are
not marked read-only.

Well, the message became too long I hope you have enough patience

Thanks a lot for reading.

buraluit
[Message sent by forum member 'buraluit' (buraluit)]

http://forums.java.net/jive/thread.jspa?messageID=213536