-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: many to many insert mapping problem
PostPosted: Tue Oct 11, 2005 7:56 am 
Beginner
Beginner

Joined: Sun Dec 05, 2004 10:25 am
Posts: 23
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 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>
<!--
        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();
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 3:01 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
Hi, I'm not sure if I understand your issue. You're headline says, you're mapping a many-to-many association, but your code say you're mapping a many-to-one association! So you've got to change the mapping of you're set.

Code:
       
<set name="services" inverse="true" cascade="all">
        <key><column name="id"></column></key>
         <many-to-many class="edu.bju.aem.util.model.Service" column=""ServerId/>
</set>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.