Ad

How To Switch An Hibernate Many-to-many Relationship From Xml To Annotation Based Configuration?

- 1 answer

<set name="Units" table="UNIT" mutable="false">
        <cache usage="read-only"/>
        <key column="ID"></key>
        <many-to-many column="U_ID" class="com.org.Unit"/>

I have declared variable in Supplier.java as:

private Set <Unit> Units;
Ad

Answer

In your entity class Supplier put:

private Set<Unit> units;

@ManyToMany
@JoinTable(name="UNIT", joinColumns={@JoinColumn(name="ID")}, 
           inverseJoinColumns={@JoinColumn(name="U_ID")}
)
public Set<Unit> getUnits() {
    return units;
}
Ad
source: stackoverflow.com
Ad