A very cool (and easy) way to know things like this is let the Hibernate Tools 
generate the Java code for you.  At the very least, you can see how it codes up 
the annotations so you don't have to think about it.  You can use the code 
as-is, modify it or throw it away.  But at least you'll know how to define your 
mappings.

The Hibernate Tools tutorials are simple and can get you up to speed to do this 
pretty quickly (this is assuming you are using the JBoss Eclipse IDE).

FWIW: I have a relation table with the same thing (relationship between A and B 
each with each own ID - there is no special "third ID" in this table, its a 
true relationship table in the ER sense).  The generated POJO spit out by the 
Hibernate Tools has a getId() annotated with @EmbeddedId with a ABId generated 
class.  Each side of the relation (getA(), getB()) is annotated with a 
@JoinColumn and a @ManyToOne.  There's some other tidbits in the generated code 
but that's the main things.

Definitely use the Hibernate Tools, it'll make your life easier.  At the very 
least to show you how to annotate your entity POJOs.  I still don't understand 
all the intracacies of these ManyToOne, JoinColumn, etc. annotations - but I 
still managed to get my stuff working by simply running the code generator over 
my existing database schema and using the annotated POJOs it gave me.  I didn't 
have to change any of the annotations it generated - it worked as-is.  My 
schema was fairly simple (10 tables, nothing fancy or abnormal about the 
relationships between tables) so your mileage may vary.

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3926688#3926688

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3926688


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to