-->
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: Composite-Id
PostPosted: Mon Feb 02, 2004 3:35 pm 
Newbie

Joined: Sat Jan 17, 2004 7:59 pm
Posts: 4
I have a Parent table Basic and child table Family and the .hbm.xml files look like this

<hibernate-mapping>
<class name="Basic" table="basic">
<id name="id" type="int" unsaved-value="null" >
<column name="basicid" sql-type="int"
not-null="true"/>
<generator class="increment"/>

</id>
...
<many-to-one name="fam" class="Family">
<column name="areaid"/>
<column name="familyid"/>
</many-to-one>
</class>
</hibernate-mapping>

and my Family file

<class name="Family" table="family">
<composite-id>
<key-property name="area" column="areaid"
type="int" length="3" />
<key-property name="familyid" column="familyid"
type="int" length="7" />
</composite-id>
...
<many-to-one name="famBasic" not-null="true"/>
<!-- associations -->
</class>
</hibernate-mapping>

how do i define family in my .java file does some one have a good example for guide
Thanks in advance.[/list]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 6:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
First it seems one of the side should be one-to-many (family one I guess) to mirror the other many-to-one.

But in your context:
Code:
Family {
Integer area;

Integer familyid;

public Integer getArea() {
  ...
}
// setter associated

//same for familyid

private Basic basic;

public Basic getBasic() {
return basic;
}
...


For a proper one-to-many mapping, check the parent-child relationship chapter.

_________________
Emmanuel


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.