Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsValidating OneToMany references to composite key components
https://www.eclipse.org/forums/index.php/mv/msg/194177/617628/#msg_617628
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?]]>Giampaolo Tomassoni2009-10-18T16:06:24-00:00Re: Validating OneToMany references to composite key components
https://www.eclipse.org/forums/index.php/mv/msg/194177/617633/#msg_617633
https://bugs.eclipse.org/bugs/show_bug.cgi?id=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.