Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mapping problem and joinColumns

 
nimo frey
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
nimo frey
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you!

now my mapping works fine:-)
 
Vijay Dharap
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic