Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Why specify man-to-one, one-to-many etc in Hibernate ?

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

what is the purpose of specifying man-to-one, one-to-many etc mappings in Hibernate ??

Apart from the compiler being able to verify that it has the right return type declared, I dont see any benefit in this.

Thanks,

J.C
 
Author
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're using mapping files, it doesn't default to mapping every attribute of a class the same way it does with annotations. So you have to explicitly tell it what you want mapped. This argument carries for many-to-one at least. Also, with many-to-one, you will often specify attributes such as:



But with default, and assuming the column attribute is implied to point to the id defined on the "one" side, you would just have the name attribute.

With one-to-many, I'm not sure. You are inside of the definition for a collection already, and it should be able to infer the type of the object.

I'm not quite sure of what the argument is for why you are required to specify @OneToMany and @ManyToOne when using annotations.
 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic