-->
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: Designfrage - Beziehung zu einer Key-Value Tabelle
PostPosted: Fri Jun 17, 2005 1:30 am 
Newbie

Joined: Tue Jun 14, 2005 4:29 am
Posts: 5
Hi,

habe eine kurze Design Frage. Nehmen wir an ich habe ein Tabelle PERSON, die eine foreign key auf eine Tabelle STATE hat. STATE besteht aus einen int primary key und einem varchar Feld. Person hat nun eine foreign key Beziehung zu STATE. STATE ist eine Tabelle, welche initial befüllt wird und dort auch keine Daten mehr zur Laufzeit hinzugefügt oder geändert werden.

Ich habe nun ein PersonDTO. Wie könnte ich nun das Mapping zu der STATE Tabelle definieren? Ich habe mir gedacht eine Klasse State zu definieren und joine die Person mit der STATE Tabelle. Ich bin aus der Hibernate Doku nicht ganz so schlau geworden. Vielen Dank für jeden Tip.


Top
 Profile  
 
 Post subject: Re: Designfrage - Beziehung zu einer Key-Value Tabelle
PostPosted: Fri Jun 17, 2005 6:55 am 
Newbie

Joined: Fri Jun 17, 2005 6:20 am
Posts: 10
Location: Hamburg, Germany
Dein Fall beschreibt eine häufig verwendete bidirektionale parent-child-relation:

Die mappings würden bei mir folgendermassen aussehen:

HIER DAS PARENT OBJECT

<!--
Mapping file for the STATE class of MyApp.
-->
<hibernate-mapping package="myApp.persistence.model" >

<class name="myApp.model.State"
table="T_STATE"
schema="mySchema"
lazy="true">

<!-- Common id property. -->
<id name="id"
type="long"
column="STATE_ID"
length="15"
unsaved-value="null">
<generator class="sequence">
<param name="sequence">state_sequence</param>
</generator>
</id>

<!-- A versioned entity. -->
<version name="version"
column="VERSION"
access="net.sf.hibernate.property.DirectPropertyAccessor"/>


<!-- Name is limited to 255 characters.-->
<property name="name"
type="string"
access="net.sf.hibernate.property.DirectPropertyAccessor">
<column name="NAME"
not-null="true"
length="30"
unique-key="UNIQUE_NAME_AT_LEVEL"/>
</property>


<!-- Use a standard parent/child relationship for persons. -->
<!-- Use it as a bag with set semantics -->
<bag
name="persons"
inverse="true"
lazy="true"
cascade="all-delete-orphan"
access="net.sf.hibernate.property.DirectPropertyAccessor">
<key column="STATE_ID"/>
<one-to-many class="Person"/>
</bag>


</class>
</hibernate-mapping>

UND NUN DAS CHILD:

<!--
Mapping file for the Person class of MyAPP.

A Person is the central entity of myAPP.


-->
<hibernate-mapping package="myapp.persistence.model">

<class name="Person"
table="T_PERSON"
schema="myApp"
lazy="true">

<!-- Common id property. -->
<id name="id"
type="long"
column="PERSON_ID"
length="10"
unsaved-value="null"
<generator class="sequence">
<param name="sequence">Person_sequence</param>
</generator>
</id>

<!-- A versioned entity. -->
<version name="version"
column="VERSION"/>


<property name="firstname"
type="string"
column="FIRSTNAME"
length="50"
not-null="false"/>

<property name="lastname"
type="string"
column="LASTNAME"
length="50"
not-null="false"/>


<!-- The other side of this bidirectional one-to-many association to person -->
<many-to-one
name="state"
foreign-key="FK_PERSON_STATE_ID"
column="STATE_ID"
class="State"
update="true"
cascade="none"
not-null="true"/>

</class>
</hibernate-mapping>


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.