• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic