File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes mapping problem and joinColumns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "mapping problem and joinColumns" Watch "mapping problem and joinColumns" New topic
Author

mapping problem and joinColumns

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
I want to map these two tables:

WOOD (Table)
---------------
ID_WOOD (Primary Key)
NAME

TREE (Table)
-------------
ID_WOOD (Primary Key AND Foreign Key)
ID_TREE (only Primary Key)
NAME

The Relationship: OneToMany (one Wood can consist of at least one Tree or more Trees)

My Table WOOD:




My Table TREE :




My Relationship does NOT work properly.

How would you map such a scenario?

(I have tried it also with PrimaryKeyJoinColumn, without success..I guess this is only for OneToOne-Relationships)

Any Ideas?
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
This HQL

"from Wood w"

returns a correct SQL:




But this HQL

"from Tree t"

returns a corrupted SQL:




This:

tree0_.wood as wood3_829_, should be a relationship (!) and has not to be in this sql-statement. So I guess, my Mapping is false! But Hibernate does not complain anything when validating the schema.

I do not know, what is wrong?


Vijay Dharap
Ranch Hand

Joined: Mar 18, 2004
Posts: 32
nimo frey wrote:
My Table TREE :



You would need to change the definition of idDocument to..


in hbm.xml

I am not master of annotations.. So I have done this using plain old xml configuration.. You can convert above two lines into Annotated version of the same.

I see following sql formed for the hql "from Tree t"


More on this can be found in example in sample testcases from hibernate

Hope this helps.

Regards,
Vijay


Vijay dharap,
<a href="http://dharapvj.wordpress.com" rel="nofollow">Blog</a>
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
thank you!

now my mapping works fine:-)
Vijay Dharap
Ranch Hand

Joined: Mar 18, 2004
Posts: 32
nimo frey wrote:thank you!

now my mapping works fine:-)


You are quite welcome!

I also learnt a thing or two while solving your problem..

Regards,
Vijay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mapping problem and joinColumns
 
Similar Threads
How to map ManyToOne relationship with Composite key?
JPA: Cascade delete for join tables with composite key
using 2 @OnetoMany annoations in one Entity Class
OneToOne composite key
Could not determine type for: java.util.Set