-->
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: Mapping Verständnis
PostPosted: Thu Sep 13, 2007 12:03 pm 
Newbie

Joined: Mon Aug 20, 2007 6:08 am
Posts: 3
Ich weiss nicht so recht wie ich folgendes mappen soll. Ich habe einen Navigationseintrag (NavEntry), diesen können mehrere Attribute (z.B. Sprache) zugeordnet werden. Einem Attribut können wiederum verschiedene Werte (Value) (z.B. deutsch, englisch, französisch,...) zugeordnet werden.

Es soll ein vordefiniertes Attribute Repository geben.

Bisher habe ich ein many-to-many Mapping zwischen NavEntry und Attribute und ein many-to-many Mapping zwischen Attribute und AttributeValue. Jedem Navigationseintrag kann zwar das selbe Attribut zugeordnet werden. Dem Attribut sollen jedoch verschiedene Werte zugeordnet werden.

z.B.
NavEntry 1 - Attribut 1 - Value A , Value B , Value C
NavEntry 2 - Attribut 1 - Value D , Value E , Value F
NavEntry 3 - Attribut 2 - Value G , Value H , Value I
NavEntry 4 - Attribut 1 - Value K , Value L , Value M

Es werden nie die selben Values einem Attribut zugeordnet.
Ich würde gerne das Mapping von Value in die Many-to-Many Beziehung zwischen NavEntry und Attribute einbringen, aber wie sieht das Mapping dazu aus?

Die Klassen:

Code:
public class NavEntry {
  private int id;
  private String path;
  private List<Attribute> attributes = new ArrayList<Attribute>();
  // get/set....
}


Code:
public class Attribute {
  private int id;
  private String label;
  private List<AttributeValue> values = new ArrayList<AttributeValue>();
  // get/set....
}


Code:
public class AttributeValue {
  private int id;
  String value;
  // get/set....
}


Bisheriges Mapping:

Code:
<class name="NavEntry" table="NavEntry">
<id name="id" type="integer">
   <generator class="native"/>
  </id>
  <property name="path" type="string"/>
  <list name="attributes" table="naventry_attributes">
    <key column="naventry_id"/>
      <index column="idx"/>
      <many-to-many column="attribute_id" class="Attribute"/>
  </list>
</class>


Code:
<class name="Attribute" table="Attribute">
  <id name="id" type="integer">
    <generator class="native"/>
  </id>
  <property name="label" type="string"/>
  <list name="values" table="attributes_values">
    <key column="attribute_id"/>
    <index column="idx"/>
    <many-to-many column="value_id" class="AttributeValue"/>
  </list>
</class>


Code:
<class name="AttributeValue" table="AttributeValue">
  <id name="id" type="integer">
    <generator class="native"/>
  </id>
  <property name="value" type="string"/>
</class>


Mein Problem: Einem Attribut können immer nur die selben Values zugenordnet werden. Ich würde gern die Values direkt im Mapping zwischen NavEntry und Attribut speichern.

z.B.
Code:
NavEntry_ID  Attribute_ID  AttributeValue_ID
1                     1                     1
1                     1                     2
1                     1                     3
2                     1                     4
2                     1                     5
2                     1                     6
3                     2                     7
3                     2                     8
3                     2                     9
4                     1                     10
4                     1                     11
4                     1                     12   


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 15, 2007 4:33 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Schaue mal bei ternary Relations oder mapkey many to many.

Bei letzterem hätte Dein NavEntry eine Map, in der der Key ein Attribut ist und der value der Attribut-Wert.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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.