If I understand you correctly, you have to do something like this:
public class Employee {
private String clientMark;
private Address address;
public String getClientMark() {
return clientMark;
}
public void setClientMark(String clientMark) {
this.clientMark = clientMark;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public static class Address {
private String street1;
private String street2;
public String getStreet1() {
return street1;
}
public void setStreet1(String street1) {
this.street1 = street1;
}
public String getStreet2() {
return street2;
}
public void setStreet2(String street2) {
this.street2 = street2;
}
}
}
Make inner class public and static that you would be able to create new object from other classes. Then add setter and getter method for inner class in outer class that the hibernate will be able to set and get the object. Next you need to edit your .hbm.xml file:
<property name="clientMark" column="CLIENT_MARK"/>
<component name="address">
<property name="street1" column="B_STREET_ADDRESS_1"/>
</component>
<component name="address">
<property name="street2" column="B_STREET_ADDRESS_2"/>
</component>
Hibernate annotation <component>
says that the named variable will be class which has some variables (<property>
in hbm.xml file). After this you can test your code like this:
Employee entity = new Employee();
entity.setClientMark("client_mark");
Employee.Address address = new Employee.Address();
address.setStreet1("street1");
address.setStreet2("street2");
entity.setAddress(address);
// entity is ready to be saved
And your result in your database will be:
|------------------------------------------------------------|
| id | CLIENT_MARK | B_STREET_ADDRESS_1 | B_STREET_ADDRESS_2 |
|------------------------------------------------------------|
| 1 | client_mark | street1 | street2 |
|------------------------------------------------------------|
I hope it helps you... ☺