-->
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: QueryException when selecting id
PostPosted: Mon Jul 03, 2006 6:36 am 
Newbie

Joined: Mon Jul 03, 2006 5:30 am
Posts: 2
Location: nantes - france
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hello,

After migrating from 2.1.8 to 3.1.3 a hql query was broken. I mean, i'm sure that the query worked before migrating.

Even though I solved the problem with this code :

Code:
         Query query = session.createQuery("SELECT ua.utilisateur FROM "
               + Affaire.class.getName()
               + " a join a.utilisateurAffaires ua WHERE a.code=?");
         query.setString(0, codeAffaire);

         List result = new ArrayList();
         for(Iterator it = query.iterate();it.hasNext();)
            result.add(((Utilisateur)it.next()).getId());

...i would like to better understand what's behind this error (certainly a misunderstood of hibernate).

This error only appears when selecting utilisateur.id and not when selecting utilisateur or utilisateur.login

Kind regards.


Hibernate version: 3.1.3

Mapping documents:

there are two entities Affaire and Utilisateur and an unidirectionnal many to many association from Affaire to Utilisateur. As the association contains two attributes, composite-element was a preferred choice.


Affaire.hbm.xml
Code:
....
    <bag
        name="utilisateurAffaires"
        table="UTILISATEUR_AFFAIRE"
        lazy="true"
        inverse="false"
           cascade="delete"
    >
        <key>
            <column name="ID_AFFAIRE" />
        </key>
        <composite-element
            class="fr.gdf.casel.metier.pojo.UtilisateurAffaire"
        >
          <property
              name="administratif"
              type="boolean"
              column="ADMINISTRATIF"
          />
          <property
              name="technique"
              type="boolean"
              column="TECHNIQUE"
          />
           
           <many-to-one
              name="utilisateur"
               class="fr.gdf.casel.metier.pojo.Utilisateur"
               column="ID_UTILISATEUR"
               outer-join="true"
           />
       </composite-element>
    </bag>
...


Utilisateur.hbm.xml

Code:
<class
    name="fr.gdf.casel.metier.pojo.Utilisateur"
    table="UTILISATEUR"
>

    <id
        name="id"
        type="long"
        column="ID_UTILISATEUR"
    >
        <generator class="increment" />
    </id>

    <property
        name="dossierWord"
        type="java.lang.String"
        column="DOSSIERWORD"
       
    />
    <property
        name="login"
        type="java.lang.String"
        column="LOGIN"
       
    />
    <property
        name="service"
        type="java.lang.String"
        column="SERVICE"
       
    />

    <!-- Associations -->
 
    <!-- bi-directional many-to-one association to Personne -->
    <many-to-one
        name="personne"
        class="fr.gdf.casel.metier.pojo.Personne"
        outer-join="true"
        cascade="all"
    >
        <column name="ID_PERSONNE" />
    </many-to-one>
    <!-- bi-directional many-to-one association to Profil -->
    <many-to-one
        name="profil"
        class="fr.gdf.casel.metier.pojo.Profil"
       
    >
        <column name="ID_PROFIL" />
    </many-to-one>

    <set
        name="affaires"
        table="UTILISATEUR_AFFAIRE"
        lazy="true"
        inverse="true"
      cascade="none"
    >
        <key>
            <column name="ID_UTILISATEUR" />
        </key>
        <many-to-many
            class="fr.gdf.casel.metier.pojo.Affaire"
            column="ID_AFFAIRE"
        />
    </set>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Code:
         Query query = session.createQuery("SELECT ua.utilisateur.id FROM "
               + Affaire.class.getName()
               + " a join a.utilisateurAffaires ua WHERE a.code=?");
         query.setString(0, codeAffaire);
         query.list();



Full stack trace of any exception that occurs:


Code:
org.hibernate.QueryException: could not resolve property: utilisateur.id of: fr.gdf.casel.metier.pojo.Affaire [SELECT ua.utilisateur.id FROM fr.gdf.casel.metier.pojo.Affaire a join a.utilisateurAffaires ua WHERE a.code=?]
   at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
   at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
   at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1265)
   at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:279)
   at org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:372)
   at org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:539)
   at org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:221)
   at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:172)
   at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
   at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)
   at org.hibernate.hql.ast.tree.DotNode.resolveSelectExpression(DotNode.java:602)
   at org.hibernate.hql.ast.HqlSqlWalker.resolveSelectExpression(HqlSqlWalker.java:736)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1881)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1821)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1392)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:553)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
   at fr.gdf.casel.metier.service.ServiceAffaire.listeIdsUtilisateur(ServiceAffaire.java:85)
   at fr.gdf.casel.presentation.actions.contexte.AffaireContextValidator.isValid(AffaireContextValidator.java:61)
   at fr.gdf.casel.presentation.actions.contexte.ModificationContexteAction.getForward(ModificationContexteAction.java:401)
   at fr.gdf.casel.presentation.actions.contexte.ModificationContexteAction.connecterAffaire(ModificationContexteAction.java:145)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
   at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
   at fr.gdf.casel.presentation.actions.CaselAction.execute(CaselAction.java:134)
   at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
   at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
   at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
   at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
   at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
   at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
   at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
   at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
   at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
   at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)



Name and version of the database you are using: Oracle 8

The generated SQL (show_sql=true): None

_________________
premature optimization is the root of all evil


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 7:54 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I don't see the old code you replaced, and could you be a bit more precise with your problem about the infos you're giving : is this the code and the exceptions you were having, what was a problem, what did you do and what changed, I don't get it easily.

One thing : why the hell are you getting the class name this way in you query ? You can write directly the class name in a simple request :

Code:
Query query = session.createQuery("SELECT ua.utilisateur FROM  Affaire a join a.utilisateurAffaires ua WHERE a.code=?");
         query.setString(0, codeAffaire);


I'd even recommend you using named parameter instead. I feel it's still clearer that indexed values. Then the code would become :
Code:
Query query = session.createQuery("SELECT ua.utilisateur FROM  Affaire a join a.utilisateurAffaires ua WHERE a.code=:codeAffaire");
         query.setString("codeAffaire", codeAffaire);


Why is this part related to your problem ?!? :
Code:
        List result = new ArrayList();
         for(Iterator it = query.iterate();it.hasNext();)
            result.add(((Utilisateur)it.next()).getId());

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 11:39 am 
Newbie

Joined: Mon Jul 03, 2006 5:30 am
Posts: 2
Location: nantes - france
hum... code is not mine and yes i use named parameters (not totally newbie!), but do you think it is related with my problem ? ;)

ok , let's give a little bit precision )

the error and the old code are decribed just after the line
"Hibernate version: 3.1.3 "

The code i give at the beginning of the message is the new one.

-> the big question is why i had to change the old code with this one?

_________________
premature optimization is the root of all evil


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.