Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dali » Validating OneToMany references to composite key components
Validating OneToMany references to composite key components [message #617628] 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?
Re: Validating OneToMany references to composite key components [message #617633 is a reply to message #617628] Tue, 20 October 2009 15:08 Go to previous 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. 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.

Thanks,
Karen
Previous Topic:IllegalStateException thrown by Dali
Next Topic:Problem with generating entity from table
Goto Forum:
  


Current Time: Thu Apr 18 03:18:54 GMT 2024

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

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

Back to the top