Forgot to mention I had a similar schema with mapping
Mapping for the many-to-many relation table (SystemUser)
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="sample" auto-import="true">
<class name="SystemUser" table="SYSTEM_USER">
<composite-id>
<key-property name="user">
<column name="id_user" sql-type="NUMBER(19)" not-null="true" length="19"/>
</key-property>
<key-property name="system">
<column name="id_system" sql-type="NUMBER(19)" not-null="true" length="19"/>
</key-property>
</composite-id>
<property name="rol" column="rol" type="string" />
</class>
</hibernate-mapping>
Mapping for User
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="sample" auto-import="true">
<class name="User" table="USER">
<id name="id" column="id_user">
<generator class="sequence">
<param name="sequence">User_SQ</param>
</generator>
</id>
<bag name="systemUsers" outer-join="false" lazy="true" optimistic-lock="true">
<key on-delete="noaction" unique="false">
<column name="id_user" sql-type="NUMBER(19)" not-null="true" length="19"/>
</key>
<one-to-many class="SystemUsers"/>
</bag>
</class>
</hibernate-mapping>
Mapping for System
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="sample" auto-import="true">
<class name="System" table="SYSTEM">
<id name="id" column="id_system">
<generator class="sequence">
<param name="sequence">System_SQ</param>
</generator>
</id>
<bag name="systemUsers" outer-join="false" lazy="true" optimistic-lock="true">
<key on-delete="noaction" unique="false">
<column name="id_system" sql-type="NUMBER(19)" not-null="true" length="19"/>
</key>
<one-to-many class="SystemUsers"/>
</bag>
</class>
</hibernate-mapping>
Code:
public class User {
private Collection systemUsers;
//....
}
Code:
public class System {
private Collection systemUsers;
//....
}
Code:
public class SystemUser {
private User user;
private System system;
private Rol rol;
//....
}
Is this OK ?
By the way, I had an error with those mapping.
And had to convert SystemUser.User type to Long and System.system type to Long too.
[/quote]