-->
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.  [ 1 post ] 
Author Message
 Post subject: Assoziationstabelle
PostPosted: Fri Nov 26, 2010 9:21 am 
Newbie

Joined: Thu Apr 08, 2010 8:47 am
Posts: 18
Hi,

ich habe Probleme mit einer Assoziationstabelle.
Zum Hintergrund: Ich habe eine Tabelle von Wörtern und eine Tabelle von Objekten. Die dazwischenliegende Assoziationstabelle soll dazu noch die Anzahl eines Wortes zu einem Objekt speichern.

Die UsedWord.hbm.xml sieht folgendermaßen aus:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="im.myp.domain.pkm.user.support">
   <class name="UsedWord" table="USED_WORD">
      <meta attribute="generated-class">im.myp.domain.pkm.user.support.AUsedWord</meta>
      <meta attribute="scope-class">public abstract</meta>
      <id name="id" type="int" column="USED_WORD_ID">
         <generator class="identity"></generator>
      </id>
      <property name="word" type="string">
         <column name="WORD" length="30" unique="true" not-null="true" />
      </property>
      ...
      <set name="objects" inverse="true" cascade="all-delete-orphan" >
         <key column="USED_WORD_ID" />
         <one-to-many class="im.myp.domain.pkm.user.support.UsedWordInPKMObject"/>
      </set>
      ...
   </class>
</hibernate-mapping>


Die PKMObject.hbm.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="im.myp.domain.pkm.object">
   <class name="PKMObject" table="PKM_OBJECT">
      <!--<meta attribute="generated-class">im.myp.domain.pkm.object.PKMObject</meta> -->
      <meta attribute="scope-class">public abstract</meta>
      <id name="id" type="int" column="PKM_OBJECT_ID">
         <generator class="identity"></generator>
      </id>
      ...
      <set name="words" inverse="true" cascade="all-delete-orphan" >
         <key column="PKM_OBJECT_ID" />
         <one-to-many class="im.myp.domain.pkm.user.support.UsedWordInPKMObject"/>
      </set>
      ...
   </class>
</hibernate-mapping>


Und die Assoziationstabelle:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="im.myp.domain.pkm.user.support">
   <class name="UsedWordInPKMObject" table="USED_WORD_IN_PKM_OBJECT">
      <meta attribute="generated-class">im.myp.domain.pkm.user.support.AUsedWordInPKMObject</meta>
      <meta attribute="scope-class">public abstract</meta>
      <composite-id name="usedWordInPKMObjectId" class="AUsedWordInPKMObjectId">
         <meta attribute="generated-class">im.myp.domain.pkm.user.support.AUsedWordInPKMObjectId</meta>
         <meta attribute="scope-class">public</meta>
         <meta attribute="use-in-equals">true</meta>
         <key-many-to-one class="UsedWord" name="usedWord" column="USED_WORD_ID" />
         <key-many-to-one class="im.myp.domain.pkm.object.PKMObject" name="pkmObject" column="PKM_OBJECT_ID" />
      </composite-id>
      <property name="counter"  type="int">
         <column name="COUNTER" length="10" not-null="true" />
      </property>
   </class>
</hibernate-mapping>


Leider klappt es nicht so wie gewünscht:
Ich kann zwar was reinschreiben und ALLES auslesen, aber nicht auf einen zusammengesetzten Key zugreifen?!

Ich bekomme dabei folgende Fehlermeldung:
Code:
Unknown entity: im.myp.domain.pkm.user.support.AUsedWordInPKMObject; nested exception is org.hibernate.MappingException: Unknown entity: im.myp.domain.pkm.user.support.AUsedWordInPKMObject
    [junit] org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: im.myp.domain.pkm.user.support.AUsedWordInPKMObject; nested exception is org.hibernate.MappingException: Unknown entity: im.myp.domain.pkm.user.support.AUsedWordInPKMObject


Testfall:
Code:
//... INIT DES OBJEKTES UND DES WORTES
//ASSOZIATIONSTABELLE:
      UsedWordInPKMObject uwInObj = new UsedWordInPKMObject();
      UsedWordInPKMObjectId uwInObjId = new UsedWordInPKMObjectId();
      
      uwInObjId.setPkmObject(pkmObject);
      uwInObjId.setUsedWord(u1);
      
      uwInObj.setUsedWordInPKMObjectId(uwInObjId);
      int counter = 10;
      uwInObj.setCounter(counter);
      
      usedWordInPKMObjectDao.save(uwInObj);
      List<UsedWordInPKMObject> uWinPKM = usedWordInPKMObjectDao.loadAll();
      assertEquals(1, uWinPKM.size());
//DIES KLAPPT WUNDERBAR
      for(int i = 0; i < uWinPKM.size();i++){
         System.out.println(uWinPKM.get(i).getUsedWordInPKMObjectId().getUsedWord().getWord());
         System.out.println(uWinPKM.get(i).getUsedWordInPKMObjectId().getPkmObject().getObjectName());
         System.out.println(uWinPKM.get(i).getCounter());
      }
//HIER CRASHT ES
      assertEquals(counter, usedWordInPKMObjectDao.load(uwInObj.getUsedWordInPKMObjectId()).getCounter());


Kann mir einer helfen bzw. habt ihr eine Idee?

Viele Grüße
MK


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.