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