//you were close you need to use annotation @OneToMany as an accumulator for JoinColumns
//of like minded entities ..here is an example
@Entity
@Table( name = "OrderItem_tbl" )
@IdClass( OrderItemID.class )
public class OrderItem {
@ManyToOne( fetch = FetchType.LAZY )
@JoinColumns( {
@JoinColumn( name = "School_Id", referencedColumnName = "School_Id", insertable = false, updatable = false ),
@JoinColumn( name = "Academic_Yr", referencedColumnName = "Academic_Yr", insertable = false, updatable = false )
} )
public Order getOrder() {
return this.order;
}
public void setOrder(Order order) {
this.order = order;
}
//test harness
public static void main(String[] args) throws Exception {
Session s = openSession( );
s.getTransaction().begin();
Order o = new Order();
o.setAcademicYear( 2000 );
o.setSchoolId( "Supelec" );
o.setSchoolIdSort( 1 );
s.persist( o );
OrderItem oi1 = new OrderItem();
oi1.setAcademicYear( 2000 );
oi1.setDayName( "Monday" );
oi1.setSchoolId( "Supelec" );
oi1.setOrder( o );
oi1.setDayNo( 23 );
s.persist( oi1 );
...
}
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
> Date: Sun, 18 Jul 2010 10:07:13 -0700
> From: glassfish_at_javadesktop.org
> To: users_at_glassfish.dev.java.net
> Subject: JPA 2.0 Persistent Map Problem
>
> I'm trying to build an entity with a persistent map. The map key is a basic type and the map value is an embeddable, like this:
>
> @ElementCollection(fetch=FetchType.EAGER)
> @MapKey(name = "language")
> @CollectionTable(schema = "jpa", name = "multilingual_string_map",
> joinColumns = @JoinColumn(name = "string_id"))
> private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
>
> LocalizedString is a simple POJO:
>
> @Embeddable
> public class LocalizedString {
> private String language;
> private String text;
> }
>
> The language field of the map value is to be used as the map key. I absolutely want to avoid duplicating this in a redundant database table column. This is precisely what @MapKey is intended for, if I understand JSR 317 correctly, though there is a bit of vagueness whether or not the map value is allowed to be an embeddable or has to be an entity.
>
> At any rate, none of the 4 JPA providers I've tried is able to handle this example. With Hibernate and Eclipselink, the closest I could get was using
>
> @MapKeyColumn(name = "language_key")
>
> instead, but this leaves me with the redundant table column "language_key" with the same values as in "language".
>
> With OpenJPA, I could resort to using
>
> @MapKeyColumn(name = "language")
>
> which makes the two columns coincide, but I'm not sure if this usage is intended by the spec. Hibernate and Eclipselink complain about a duplicate column mapping in this case.
>
> So who's right and who's wrong....?
>
> Sorry for this messy layout, this forum engine does not seem to support embedded HTML. I posted a longer version of this example together with details regarding the individual JPA providers in my blog:
>
> http://hwellmann.blogspot.com/2010/07/jpa-20-mapping-map.html
>
> Best regards,
> Harald
> [Message sent by forum member 'hwellmann']
>
> http://forums.java.net/jive/thread.jspa?messageID=477901
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
_________________________________________________________________
The New Busy is not the old busy. Search, chat and e-mail from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_3