i have a case want to map building name/value pair, here is the mapping xml, sql and class(simplified).
i make 2 class for the mapping, but hibernate does map the name/vale pair in the properties.
how can i make hibernate map the buildingproperties in building
hibernate version:hibernate-3.2.2.ga
Code:
create table building
(
id integer not null,
address varchar(256) not null,
primary key (id)
);
create table buildingproperty
(
buildingid integer not null,
name varchar(32) not null,
value varchar(256) not null,
primary key(buildingid, name)
);
public class Building
{
private int id;
private String address;
private Properties buildingproperties;
// getters and setters
public String getProperty(String name)
{
return buildingproperties.getProperty(name);
}
public String setProperty(String name, String value)
{
buildingproperties.setProperty(name, value);
}
}
// this class make for mapping
public class BuildingProperty
{
private int buildingid;
private String name;
private String value;
// getters and setters
}
<hibernate-mapping>
<class name="Building" table="building">
<id name="id" type="int">
<generator class="native"/>
</id>
<property name="address" type="java.lang.String" not-null="true"/>
<map name="buildingproperties">
<key column="id"/>
<map-key column="name" type="java.lang.String"/>
<element column="value" type="java.lang.String"/>
<!--
<one-to-many class="BuildingProperty"/>
-->
</map>
</class>
<class name="BuildingProperty" table="buildingproperty">
<composite-id>
<key-property name="buildingid" type="int"/>
<key-property name="name" type="java.lang.String"/>
</composite-id>
<property name="value" type="java.lang.String" not-null="true"/>
</class>
</hibernate-mapping>