-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate problems
PostPosted: Tue Jun 05, 2007 6:16 am 
Newbie

Joined: Tue Jun 05, 2007 5:59 am
Posts: 4
I have a database which contains a table with a composite id. The composite id contains an id of type int and a direction of type bit. When I insert something in the table, I must save to records: one record with an id, a direction and some data, and the other record with the same id as the first one, the opposite direction and some other data.

How should i map that table and how should i write the java code in this case?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 9:06 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

You should save two objects which mapping with composite-id

your mapping file may like
Code:
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>     
    <class
        name="lk.wts.Test"
        table="Test"
    >
<composite-id   
        >
                     <key-property
                        name="id"
                        type="java.lang.String"
                        column="id"
                />

                     <key-property
                        name="direction"
                        type="java.lang.String"
                        column="direction"
                />

      </composite-id>

  <property
            name="otherData"
            type="java.lang.String"
            update="false"
            insert="false"
            column="otherData"
        />
</class>

</hibernate-mapping>



Test a=new Test();
a.setId("id1");
a.setDirection("dir1");
a.setOtherData("data1");
session.save(a);
Test b=new Test();
b.setId("id1");
b.setDirection("dir2");
b.setOtherData("data2");

session.save(b);


Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 05, 2007 9:21 am 
Newbie

Joined: Tue Jun 05, 2007 5:59 am
Posts: 4
The id property of the composite-id must be of type int and must be generated by the database server. My application isn't the only one using the database.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.