Hi.
I can't write hql query which select from Users and Groups like sql:
Code:
SELECT u.user_id, u.username, g.group_name FROM users u, user_groups ug,
groups g WHERE u.user_id = ug.user_id AND ug.group_id = g.group_id
Users.hbm.xml
Code:
<hibernate-mapping>
<class name="model.Users" table="users">
<id name="user_id">
<generator class="identity" />
</id>
<property name="username" type="string" />
<property name="first_name" type="string" />
<property name="middle_name" type="string" />
<property name="last_name" type="string" />
<property name="password" type="string" />
<set name="groups" table="user_groups" inverse="false" lazy="true" fetch="select" cascade="all" >
<key>
<column name="user_id" not-null="true" />
</key>
<many-to-many entity-name="model.Groups">
<column name="group_id" not-null="true" />
</many-to-many>
</set>
<!--one to many users -> incydent -->
<set name="incydents" table="incydents" inverse="true" lazy="true" fetch="select">
<key>
<column name="user_id" not-null="true" />
</key>
<one-to-many class="model.Incydents" />
</set>
<!-- one to many users -> incydent -->
</class>
</hibernate-mapping>
Code:
Groups.hbm.xml
<hibernate-mapping>
<class name="model.Groups" table="groups">
<id name="group_id">
<column name="group_id" />
<generator class="identity" />
</id>
<property name="group_name" />
<property name="group_desc" />
<set name="users" table="user_groups" inverse="true" lazy="true" fetch="select">
<key>
<column name="group_id" not-null="true" />
</key>
<many-to-many entity-name="model.Users">
<column name="user_id" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
Incydents.hbm.xml
Code:
<hibernate-mapping>
<class name="model.Incydents" table="incydents">
<id name="inc_id" column="inc_id">
<generator class="identity" /> <!--native-->
</id>
<property name="inc_desc" />
<many-to-one name="users" class="model.Users" fetch="select">
<column name="user_id" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>
Thx for all ;-)