* Hibernate Version 2.1.4
* Postgresql 7.4
* Mapping documents:
-
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.useitgroup.ui2005.domain">
<class name="Land" table="Land">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<property name="naam" type="string"/>
<property name="code" type="string"/>
<bag name="plaatsen" inverse="true" lazy="false" cascade="save-update">
<key column="landId"/>
<one-to-many class="Plaats"/>
</bag>
</class>
</hibernate-mapping>
-
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.useitgroup.ui2005.domain">
<class name="Plaats" table="Plaats">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<property name="postcode" type="string"/>
<property name="gemeente" type="string"/>
<many-to-one name="land" column="landId"/>
</class>
</hibernate-mapping>
So the same in a schema here we have 2 tables:
[Plaats]..............[Land]
Id.............. /--->.Id
LandId.----/........Naam
Postcode............Code
Gemeente
* [code] private void PostcodeTest()
{
Configuration cfg = new Configuration();
SessionFactory sf = null;
Session s = null;
Transaction tx;
List landen;
Plaats[] plaatsen;
ListIterator listiterator;
Land land;
Plaats plaats;
int t;
try
{
cfg.addClass(Plaats.class);
cfg.addClass(Land.class);
cfg.setProperty(Environment.HBM2DDL_AUTO, "create");
cfg.setProperty(Environment.SHOW_SQL, "true");
sf = cfg.buildSessionFactory();
s = sf.openSession();
tx = s.beginTransaction();
land = new Land("Belgi