-->
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.  [ 3 posts ] 
Author Message
 Post subject: MappingException: collection was not an association
PostPosted: Mon Aug 07, 2006 3:15 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
hi all!

I have a many-to-many association between TAETIGKEIT and BERECHTIGUNG with the following mapping:

Code:
<hibernate-mapping>
    <class name="najsre7.model.Taetigkeit" table="TTAETIGKEIT" >
        <id name="id" type="java.lang.Integer">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
            <column name="ILAUFNUMMER" precision="22" scale="0" />
            <generator class="sequence">
                <param name="sequence">SEQ_TTAETIGKEIT</param>
            </generator>
        </id>
        <timestamp name="mutDatum" column="DMUTDAT" />
        <property name="taetigkeit" type="java.lang.String">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
            <column name="STAETIGKEIT" length="50" not-null="true" />
        </property>
        <property name="beschreibung" type="java.lang.String">
           <meta attribute="use-in-tostring">true</meta>
           <meta attribute="use-in-equals">true</meta>
           <column name="SBESCHREIBUNG" length="200" />
        </property>
        <property name="mutUser" type="java.lang.String">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
            <column name="SMUTUSER" length="50" not-null="true" />
        </property>
        <property name="stvUser" type="java.lang.String">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
            <column name="SSTVUSER" length="50" />
        </property>
        <set name="profile" table="TPROFIL_TAETIGKEIT"  fetch="join" >
          <key column="FK_TTAETIGKEIT_ILAUFNR" />
          <many-to-many  column="FK_TPROFIL_ILAUFNR" class="najsre7.model.Profil" />
        </set>
        <set name="berechtigungen" table="TBERECHTIGUNG" >
         <key column="FK_TTAETIGKEIT_ILAUFNR"/>
          <composite-element class="najsre7.model.Berechtigung">
              <property name="mutDatum" type="java.util.Date">
                  <meta attribute="use-in-tostring">true</meta>
                  <meta attribute="use-in-equals">true</meta>
                  <column name="DMUTDAT" length="10" not-null="true" />
              </property>
              <property name="mutUser" type="java.lang.String">
                  <meta attribute="use-in-tostring">true</meta>
                  <meta attribute="use-in-equals">true</meta>
                  <column name="SMUTUSER" length="10" not-null="true" />
              </property>
              <property name="stvUser" type="java.lang.String">
                  <meta attribute="use-in-tostring">true</meta>
                  <meta attribute="use-in-equals">true</meta>
                  <column name="SSTVUSER" length="10" />
              </property>
              <many-to-one name="aktion" column="FK_TAKTION_ILAUFNR" class="najsre7.model.Aktion"/>   
              <many-to-one name="transaktion" column="FK_TTRANSAKTION_ILAUFNR" class="najsre7.model.Transaktion"/>   
          </composite-element>
      </set>        
    </class>
</hibernate-mapping>


My Criteria query looks like this:

Code:
Criteria criteria = session.createCriteria(Benutzer.class).setResultTransformer(
                  Criteria.ALIAS_TO_ENTITY_MAP);
            criteria.createAlias("profile", "profile").setResultTransformer(
                  Criteria.ALIAS_TO_ENTITY_MAP);
            criteria.createAlias("profile.taetigkeiten", "taetigkeiten").setResultTransformer(
                  Criteria.ALIAS_TO_ENTITY_MAP);
            criteria.createAlias("taetigkeiten.berechtigungen", "berechtigungen");
            // get all actions and transactions of a benutzer

            criteria.add(Restrictions.eq("benutzerName", userId));

            List resultList = criteria.list();


I want to get all BERECHTIGUNGEN which are associated with a specified BENUTZER, but the following exception occurs:

Code:
2006-08-07 09:00:55,078 ERROR org.springframework.orm.hibernate3.HibernateSystemException: collection was not an association: najsre7.model.Taetigkeit.berechtigungen; nested exception is org.hibernate.MappingException: collection was not an association: najsre7.model.Taetigkeit.berechtigungen
Caused by: org.hibernate.MappingException: collection was not an association: najsre7.model.Taetigkeit.berechtigungen
   at org.hibernate.type.CollectionType.getAssociatedEntityName(CollectionType.java:380)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathEntityName(CriteriaQueryTranslator.java:207)


Any ideas what's wrong with my mapping??

Regards Angela


Top
 Profile  
 
 Post subject: when do you get the exception?
PostPosted: Mon Aug 07, 2006 4:00 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
During the hibernate init stages?


Top
 Profile  
 
 Post subject: Re: when do you get the exception?
PostPosted: Mon Aug 07, 2006 4:33 am 
Regular
Regular

Joined: Mon Mar 06, 2006 6:18 am
Posts: 95
Location: Bern, Switzerland
sagimann wrote:
During the hibernate init stages?

no, only if i execute the query.

I created a additional mapping file now for TBERECHTIGUNG:

Code:
<hibernate-mapping>
    <class name="najsre7.model.Berechtigung" table="TBERECHTIGUNG" >
        <composite-id>
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
         <key-many-to-one name="taetigkeit" class="najsre7.model.Taetigkeit" column="FK_TTAETIGKEIT_ILAUFNR" />
         <key-many-to-one name="transaktion" class="najsre7.model.Transaktion" column="FK_TTRANSAKTION_ILAUFNR" />
         <key-many-to-one name="aktion" class="najsre7.model.Aktion" column="FK_TAKTION_ILAUFNR" />         
        </composite-id>
        <timestamp name="mutDatum" column="DMUTDAT" />
        <property name="mutUser" type="java.lang.String">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
            <column name="SMUTUSER" length="10" not-null="true" />
        </property>
        <property name="stvUser" type="java.lang.String">
            <meta attribute="use-in-tostring">true</meta>
            <meta attribute="use-in-equals">true</meta>
            <column name="SSTVUSER" length="10" />
        </property>
       <many-to-one name="aktion" class="najsre7.model.Aktion" column="FK_TAKTION_ILAUFNR" lazy="false" fetch="join" insert="false" update="false"/>
       <many-to-one name="taetigkeit" class="najsre7.model.Taetigkeit" column="FK_TTAETIGKEIT_ILAUFNR" lazy="false" fetch="join" insert="false" update="false"/>
       <many-to-one name="transaktion" class="najsre7.model.Transaktion" column="FK_TTRANSAKTION_ILAUFNR" lazy="false" fetch="join" insert="false" update="false"/>
    </class>
</hibernate-mapping>


Taetigkeit.hbm.xml:
Code:
        <set name="berechtigungen" inverse="true" cascade="persist,merge,save-update">
         <key column="FK_TTAETIGKEIT_ILAUFNR" />
         <many-to-many class="najsre7.model.Berechtigung" />
      </set>


But then i get the following error while starting:

Code:
2006-08-07 10:27:33,313 ERROR Servlet /ndbjsre7 threw load() exception in (StandardContext.java:3919)
org.hibernate.MappingException: Foreign key (FKEB00DA60FF9481EF:berechtigungen [elt])) must have same number of columns as the referenced primary key (TBERECHTIGUNG [FK_TTRANSAKTION_ILAUFNR,DMUTDAT,SMUTUSER])


These are my tables:

Table TBERECHTIGUNG:
- FK_TAKTION_ILAUFNR
- FK_TTAETIGKEIT_ILAUFNR
- FK_TTRANSAKTION_ILAUFNR
- MUTUSER
- MUTDAT

Table TTRANSAKTION:
- ILAUFNUMMER
- STRANSAKTION
- MUTUSER
- MUTDAT

Table TAKTION
- ILAUFNUMMER
- SAKTION
- MUTUSER
- MUTDAT

Table TRANSAKTION_TAKTION:
- FK_TAKTION_ILAUFNR
- FK_TTRANSAKTION_ILAUFNR
- MUTUSER
- MUTDAT

Table TTAETIGKEIT
- ILAUFNUMMER
- SAKTION
- MUTUSER
- MUTDAT

How should my mappings look like?

Regards Angela


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.