Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.1
Mapping documents:
For UserTypes Table:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.useradmin.beans.admin.UserTypes" table="usertypes" lazy="true">
<id name="id" column="typeid" unsaved-value="0">
<generator class="increment" />
</id>
<property name="typeName" column="typeName" not-null="true" length="50"/>
<set name="users" cascade="all" inverse="false" >
<key column="userid"/>
<one-to-many class="com.useradmin.beans.admin.User"/>
</set>
</class>
</hibernate-mapping>
For User Table:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.useradmin.beans.admin.User" table="users" >
<id name="id" column="userid" unsaved-value="0">
<generator class="increment" />
</id>
<many-to-one name="usertypes" column="typeid" update="false" class="com.useradmin.beans.admin.UserTypes"
not-null="true" lazy="no-proxy" >
</many-to-one>
<property name="firstname" column="firstname" not-null="false" length="50"/>
<property name="lastName" column="lastname" not-null="false" length="16"></property>
<property name="address" column="address" not-null="false" length="16"/>
<property name="email" column="email" not-null="false"/>
<property name="login" column="login" not-null="false" length="50"></property>
<property name="password" column="password" not-null="false" length="50"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
List<UserTypes> list = session.createQuery("from UserTypes").list();
This is returning the records from User class as well.
Full stack trace of any exception that occurs:
There is not any exception.
Problem is after mapping both of these classes when i execute the HQL
"from UserTypes" its returning the data from user class as well.
I am getting both tables records from this query..
Name and version of the database you are using:
MSSQL SERVER
The generated SQL (show_sql=true):
Hibernate: select usertypes0_.typeid as typeid1_, usertypes0_.typeName as typeName1_ from usertypes usertypes0_
Hibernate: select user0_.userid as userid3_, user0_.typeid as typeid3_, user0_.firstname as firstname3_, user0_.lastname as lastname3_, user0_.address as address3_, user0_.email as email3_, user0_.login as login3_, user0_.password as password3_ from users user0_