Hibernate Manny-to-Many Mapping

Posted by Jagadeesh VP | Posted in


package com.vpj;

import java.util.Set;
import com.vpj.Boo;

public class Foo {
private String fooId;
private Storing name;

private Set<Boo> boo;

/* Getters & Setters */
}

package com.vpj;

import java.util.Set;
import com.vpj.Foo;

public class Boo {
private String booId;
private String name;

private Set<Foo> foo;

/* Getters & Setters */
}

.hbm.xml :

...
<class type="com.vpj.Foo">
<id name="id" column="id">
<genetator class="increment" />
</id>

<property name="name" type="string" column="name" />

<set name="boo" table="Foo_Boo">
<key column="fooId" />
<many-to-many column="booId" class="Boo" />
</set>
</class>

<class type="com.vpj.Boo">
<id name="id" column="id">
<generator class="increment" />
</id>

<property name="name" type="string" column="name" />

<set name="foo" table="Foo_Boo">
<key column="booId" />
<many-to-many column="fooId" class="Foo" />
</set>
</class>
...

Comments (0)

Post a Comment