Hi, I think you may need to do a one-to-many mapping in the class com.test.dto.Address.
You have the many-to-one mapping in the StudentDTO class with a Address class reference "address", and you can use it to find out the street a specific student lives in.
Also you need to have a one-to-many mapping with a StudentDTO reference in your Address class so that you can use it to find who lives in a specific street.
I am not good at English so you may just test the following codes in case I didnt make myself clear.
Noted that a column name"addressId" has been added to the property "address"
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.test.dto.StudentDTO" table="TAB_STUDENT">
<!-- Shared primary key generator, dependend on "user" property -->
<id name="studentId" column="STUDENT_ID">
<generator class="increment" />
</id>
<property name="firstName" column="FIRST_NAME" />
<property name="lastName" column="LAST_NAME" />
<many-to-one name="address" column="addressId" class="com.test.dto.Address"
cascade="all" not-null="true" />
</class>
</hibernate-mapping>
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.test.dto.Address" table="TAB_ADDRESS">
<!-- Shared primary key generator, dependend on "user" property -->
<id name="addressId" column="ADDRESS_ID">
<generator class="native" />
</id>
<property name="street" column="ADDRESS_STREET" />
<property name="city" column="ADDRESS_CITY" />
<property name="zipcode" column="ADDRESS_ZIP_CODE" />
<property name="state" column="ADDRESS_STATE" />
<set name="students" inverse="true">
<key column="addressId" />
<one-to-many class="com.test.dto.StudentDTO" />
</set>
</class>
</hibernate-mapping>
Also you need to add the following into your Address class. Noted that the set name"student" is the "student" used in your mapping above.
Code:
Set<StudentDTO> students = new HashSet<StudentDTO>();