Validating OneToMany references to composite key components [message #492096] |
Sun, 18 October 2009 16:06 |
Giampaolo Tomassoni 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
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04338 seconds