Wednesday, June 29, 2005
All possible kinds of relationship for Hibernate mapping. Combined into a table format for easier referencing. Taken from Xylax.net

Relationship Bidirectionality

Simple Relationship (one-to-one)

Java Code
Bar Foo.getBar() // returns corresponding Bar instance

Hibernate Mapping

  <class name="Foo" table="foo">
      ...
      <one-to-one name="bar" class="Bar"/>
  </class>
  
Yes. Just add a similar mapping and Foo property to Bar

Simple Reference (many-to-one)

Java Code
Bar Foo.getBar() // returns corresponding Bar instance

Hibernate Mapping

  <class name="Foo" table="foo">
       ...
       <many-to-one name="bar" class="Bar" column="bar_id"/>
  </class>
  
Yes. Just add a similar mapping and Foo property to Bar. Just add an extra column in Bar's table called foo_id

Basic Collection (one-to-many)

Java Code
Set Foo.getBars() // returns a collection of Bar instances

Hibernate Mapping

   <class name="Foo" table="foo">
       ...
       <set role="bars" table="bar">
           <key column="foo_id"/>
           <one-to-many class="Bar"/>
       </set>
   </class>
  
Relationship can be established both ways. Just refer to the many-to-one relationship

Collection (many-to-many)

Java Code
Set Foo.getBars() // returns a collection of Bar instances

Hibernate Mapping

   <class name="Foo" table="foo">
        ...
        <set role="bars" table="foo_bar">
              <key column="foo_id"/>
              <many-to-many column="bar_id" class="Bar"/>
        </set>
   </class>
  
Relationship can be established both ways. Just refer to the many-to-one relationship

Glossary:
First-rank classes are those with their own mapping definition for Hibernate entities and must always be explicitly persisten.
Second-rank classes are those with enclosed by first-rank classes or persisted throught associations or relationships with a first-rank class.

Source:
Xylax.net
6:19 AM
posted by Ericos @

Sunday, June 12, 2005
Hibernate is one of the leading Object-Relational Mapping framework available in the open-source realm of Java. Instead of EJB from the de-facto J2EE standard, Hibernate allows developers to work with POJOs (Plain Old Java Objects). EJB introduces many unncessary artifacts for even very data-handling simple tasks. On the other hand, POJOs are non-intrusive and non-restrictive.
4:49 PM
posted by Ericos @


REFERENCES
JBoss Hibernate Apache MySQL