Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dali » Validating OneToMany references to composite key components(JSR 220/Java Persistence API isn't for the faint of heart)
Validating OneToMany references to composite key components [message #492096] Sun, 18 October 2009 16:06 Go to next message
Giampaolo Tomassoni is currently offline Giampaolo TomassoniFriend
Messages: 8
Registered: August 2009
Junior Member
Verification wrongly fails on OneToMany relationships referring pojos which use them as composite-key components.

In this example:

@Entity
public class A implements Serializable {
    @Id
    protected Integer id;

    public Integer getId()
    { return(id); }


    @OneToMany(mappedBy = "a")
    protected List<C> cs;

    public List<C> getCs()
    { return(cs); }

    ....

}

@MappedSuperclass
public class CPK implements Serializable {
    @Id
    @ManyToOne(optional = false)
    @JoinColumn(name = "idA")
    protected A a;

    public A getA()
    { return(a); }


    @Id
    protected Integer otherIdComponent;

    public Integer getOtherIdComponent()
    { return(otherIdComponent); }

    ....

}

@Entity
@IdClass(CPK.class)
public class C extends CPK {

    ....

}


the OneToMany(...) row in class A gets marked by the error "Attribute named "a" has invalid mapping for this relationship".

By ignoring the error, compiling and running the resulting code, it is evident that the OneToMany relation works as expected.

The problem also happens with Deli 2.2.1 .

Please note that this problem may be raised by the fact that the JPA standard (see "JSR 220: Enterprise JavaBeansTM,Version 3.0 - Java Persistence API" par. 2.1.4) doesn't explicitly enlist a ManyToOne relation as a possible primary key or composite key component.

In practice, the JoinColumn of the ManyToOne relation is to be seen as the effective key or key component, not the relation itself. Thereby, at least one of the most common JPA tools (Hibernate) do allow this construct since it is much more concise than any JPA-strict equivalent (in example, class CPK could define an "@Id Integer idA" and then use the same field in a non-id ManyToOne relation, which defeats any purpouses of concise description of a database structure).

Any comment? Do I have to file a bug in order to let developers know of this?

[Updated on: Sun, 18 October 2009 16:06]

Report message to a moderator

Re: Validating OneToMany references to composite key components [message #492481 is a reply to message #492096] Tue, 20 October 2009 15:08 Go to previous messageGo to next message
Karen Butzke is currently offline Karen ButzkeFriend
Messages: 220
Registered: July 2009
Senior Member
This problem will be fixed in the 3.0 release of Dali, actually in Milestone 3. The 1.0 spec and the reference implementation did not support @Id on a ManyToOne mapping so Dali is reading this mapping as an Id and not as a ManyToOne mapping. bug 258689 provided derived Id support.

In 3.0 M3 you will need to have a 2.0 JPA faceted project to get the proper support for this. If you want this support in the Dali 2.2.1 stream the bug will need to be entered against Hibernate since this support is specific to Hibernate and not the generic JPA implementation.

Thanks,
Karen
Re: Validating OneToMany references to composite key components [message #493003 is a reply to message #492481] Thu, 22 October 2009 16:27 Go to previous message
Giampaolo Tomassoni is currently offline Giampaolo TomassoniFriend
Messages: 8
Registered: August 2009
Junior Member
Karen, thank you for your reply.

I can probably wait for the 3.0 release of Dali.

Giampaolo
Re: Validating OneToMany references to composite key components [message #617641 is a reply to message #492481] Thu, 22 October 2009 16:27 Go to previous message
Giampaolo Tomassoni is currently offline Giampaolo TomassoniFriend
Messages: 8
Registered: August 2009
Junior Member
Karen, thank you for your reply.

I can probably wait for the 3.0 release of Dali.

Giampaolo
Previous Topic:How can Primary Key classes be automatically generated?
Next Topic:Extensibility of GenerateEntityWizard and GenerateEntityFromShemaWizard
Goto Forum:
  


Current Time: Wed Nov 26 11:51:55 GMT 2014

Powered by FUDForum. Page generated in 0.01643 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software