This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


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
 
GeeCON Prague 2014
 
subject: mapping problem and joinColumns