aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes @ManyToOne and @OneToMany : 2 primary keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "@ManyToOne and @OneToMany : 2 primary keys" Watch "@ManyToOne and @OneToMany : 2 primary keys" New topic
Author

@ManyToOne and @OneToMany : 2 primary keys

Dupon David
Greenhorn

Joined: Aug 11, 2006
Posts: 19
Hello.
as I still did not solve my problem, I will try to reformulate my question I want to make request EJB3 QL with joint.
here my tables:



Knowing that I have the following table which has like cl�s primary both cl�s primary of the tables the preceding one.



knowing that cardinality between these tables and ManyToMany, my question and to know if so that I can make a join

between my tables I must create tables interm�diates which contain that the primary keys like umlssnmi_wasnmi kind

and whoart_wasnmi for example, and to make @JoinTable; or the table "wasnmi" will join the tables.

I tried to implement :

For table WHOART:

For UMLSSNMI table:



The TermProjPK class which contains the primary keys of table WASNMI:



For WASNMI table:



That does not function, because I do not know how I can reach the fields ` MODIF' and ` SRC' of the table ` WASNMI' starting from TermSource object.



Somebody already made there?. I thank you in advance

[ November 15, 2006: Message edited by: Dupon David ]

[ November 17, 2006: Message edited by: Bear Bibeault ]
[ November 17, 2006: Message edited by: Bear Bibeault ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Well you could always not map your join table, and map the two ends of your many-to-many relationship pointing to your join table.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Dupon David
Greenhorn

Joined: Aug 11, 2006
Posts: 19
Hi,
I thank you for this solution which appears tempting,
but my superior want imperatively that I use EJB3 with JBoss 4.0.4 and hibernate.
would have an other solution? I thank you in advance
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Um, my solution is using EJB3 and Hibernate. Check out the documentation on mapping Many to Many.

Mark
Dupon David
Greenhorn

Joined: Aug 11, 2006
Posts: 19
Hi,
In fact, the annotation @ManyToMany does not function for my case, because my table WASNMI is not simply a table of joint, but it contains of another fields that the foreign keys.

I implemented as follows:

TermSource and SnomedInter must have a collection of TermProj, and not of TermProPK. In the same way, TermProj must only have a direct bond towards 1 TermSource and 1 SnomedInter in addition. It is HIBERNATE which is given the responsability to manage the keys themselves! Us, only the objects are managed.

TermSource :


SnomedInter :


TermProjPk :


TermProj :



it remains me to be known how I can reach a SnomedInter object to leave a TermSource object!! I tested implementer as follows:



an idea?

[ November 17, 2006: Message edited by: Dupon David ]

[ November 17, 2006: Message edited by: Dupon David ]
[ November 17, 2006: Message edited by: Dupon David ]
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
David,

You keep looking for an answer, but you don't seem to be paying attention to the answers you are getting. You certainly didn't seem to even look past the basic chapter on OR mapping in our JPA book. Take a look in Chapter 8. There is a "Mapping Relationship State" section there that discusses your exact association table situation.

-Mike


-Mike
Pro JPA 2: Mastering the Java Persistence API
 
Consider Paul's rocket mass heater.
 
subject: @ManyToOne and @OneToMany : 2 primary keys