-->
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: how to config the *.hbm.xml for one to many? THX!
PostPosted: Thu Dec 18, 2008 3:45 am 
Newbie

Joined: Thu Dec 18, 2008 3:39 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.2


Code:
create table tb1(
dbid1 int not null,
dbid2 int not null,
value1 int ,
primary key(dbid1,dbid2)

)

create table tb2(
dbid1 int not null,
dbid2 int not null,
value3 int ,
primary key(dbid1,dbid2,vlaue3)
)

ALTER TABLE tb2 ADD
    CONSTRAINT FK_tb2 FOREIGN KEY
    (
        dbid1,dbid2
    ) REFERENCES tb1(
        dbid1,dbid2
    )
GO

tb1-tb2 is one-to-many。

        <class name="Tb1Bean" table="tb1">
           
                <composite-id >
                     <key-property name = "dbid1" column = "dbid1" type="java.lang.Integer"/>
                     <key-property name = "dbid2" column = "dbid2" type="java.lang.Integer"/>
                </composite-id>
           
                <property name="value1" column="value1" type="java.lang.Integer"/>

               
    <set name="tb2List" table="tb2" cascade="all" order-by="value3 asc">
                            <key column="dbid1" not-null="true" />
                            <key column="dbid2" not-null="true" />
                            <one-to-many class="Tb2Bean" />
                </set>
       
        </class>

        <class name="Tb2Bean" table="tb2">   
                <composite-id >
                     <key-property name = "dbid1" column = "dbid1" type="java.lang.Integer"/>
                     <key-property name = "dbid2" column = "dbid2" type="java.lang.Integer"/>
                                         <key-property name = "value3" column = "value3" type="java.lang.Integer"/>
                </composite-id>
       
        </class>



the <set> is bad format ,two <key> is not allowed.
how to??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2008 6:25 am 
Newbie

Joined: Tue Nov 11, 2008 5:36 am
Posts: 5
Location: Stockholm, Sweden
If you want to map multiple columns to the key in your set, do that by specifying multiple columns inside a single key element.

See: http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-key

"(1) column (optional): The name of the foreign key column. This may also be specified by nested <column> element(s). "


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.