Hibernate 3.0
Postgres 8.0
I have looked at the Hibernate documentation but I am confused on something. I have 2 classes(Server, Service) In the database I have 3 tables server, service, and serverservice(many to many table). OK my mapping file I have a set service which are the services that a server has. I am haveing troubles when I try to insert a service. Here are the mapping files and code I am using to insert. I know it is a problem with the mapping file but I am not sure how to set this up properly.
server mapping file
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="edu.bju.aem.util.model.Server" table="server" schema="public">
<id name="id" type="long">
<column name="id" />
<generator class="sequence" >
<param name="sequence">server_id_seq</param>
</generator>
</id>
<many-to-one name="os" class="edu.bju.aem.util.model.OS" cascade="all" unique="true">
<column name="fkos" not-null="true" />
</many-to-one>
<property name="name" type="string">
<column name="sname" length="25" />
</property>
<property name="description" type="string">
<column name="description" />
</property>
<property name="production" type="boolean">
<column name="production" not-null="true" />
</property>
<set name="services" inverse="true" cascade="all">
<key><column name="id"></column></key>
<one-to-many class="edu.bju.aem.util.model.Service"/>
</set>
</class>
</hibernate-mapping>
service mapping fileCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="edu.bju.aem.util.model.Service" table="service" schema="public">
<id name="id" type="long">
<column name="id" />
<generator class="sequence" >
<param name="sequence">service_id_seq</param></generator>
</id>
<property name="name" type="string">
<column name="sname" length="0" not-null="true" unique="true" />
</property>
</class>
</hibernate-mapping>
save code is in a few clases here is the code from the object itself and the dao which follows the dao pattern from the updated caveat code
Code:
public void save()throws Exception{
ServerDAO sdao = DAOFactory.HIBERNATE.getServerDAO();
sdao.save(this);
}
public void save(Server server) {
Transaction tx = this.getSession().beginTransaction();
Server ser = this.makePersistent(server);
tx.commit();
}