How am I gonna do this in hibernate:
Code:
select a.person_name, b.address, b.zip, from Person a, Address b where a.address_id = b. address_id
I tried <join> but that didnt work, Im using hibernate2.
//My Class:
Code:
package za.co.easypay.easycredit;
public class Person {
private int id;
private String name;
private String address;
private String zip;
public Person() {
super();
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
}
//My Mapping File
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="za.co.easypay.easycredit.Person"
table="Person"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>
<id
name="id"
column="person_id"
type="int"
unsaved-value="null"
>
<generator class="assigned"/>
</id>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="name"
/>
<join table="address">
<key column="address_id"/>
<property name="zip" column="zip"/>
<property name="address" column="address"/>
</join>
</class>
</hibernate-mapping>
//The sql generated
Code:
Hibernate: select person0_.person_id as person_id, person0_.name as name from Person person0_
Am I doing something wrong, I did read the manual at 6.1.17 but that didnt help much.