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.  [ 7 posts ] 
Author Message
 Post subject: hibernate queries not working for composite keys/ids???
PostPosted: Mon Jan 17, 2005 1:49 pm 
Beginner
Beginner

Joined: Wed Dec 08, 2004 9:17 am
Posts: 25
Hi all,

I am trying to execute a "simple"
Code:
from VersionImpl as v where v.id = ? and v.workspaceId = ?
query with Hibernate.

What I am getting is a
Code:
Exception in thread "main" org.springframework.orm.hibernate.HibernateQueryException: path expression ends in a composite value: versionimp0_.id [from de.vodafone.rnp.core.business.persistence.jdo.VersionImpl as v where v.id = ? and v.workspaceId = ?]; nested exception is net.sf.hibernate.QueryException: path expression ends in a composite value: versionimp0_.id [from de.vodafone.rnp.core.business.persistence.jdo.VersionImpl as v where v.id = ? and v.workspaceId = ?]
net.sf.hibernate.QueryException: path expression ends in a composite value: versionimp0_.id [from de.vodafone.rnp.core.business.persistence.jdo.VersionImpl as v where v.id = ? and v.workspaceId = ?]
   at net.sf.hibernate.hql.PathExpressionParser.getWhereColumn(PathExpressionParser.java:375)
   at net.sf.hibernate.hql.WhereParser.doPathExpression(WhereParser.java:352)
...


My mapping file looks like
Code:
<hibernate-mapping schema="dbo" package="de.vodafone.rnp.core.business.persistence.hibernate">
    <class name="VersionImpl" table="funver" proxy="VersionImpl" lazy="true">
        <composite-id>
            <key-property name="id"/>
            <key-property name="workspaceId"/>
        </composite-id>
        <property name="id" type="integer" column="ver_nr"/>
        <property name="workspaceId" type="integer" column="arb_lfdnr" insert="false" update="false"/>
        <property name="name" type="string" column="ver_name"/>
        <property name="creationDate" type="date" column="ver_ang_zeit"/>
        <property name="inconsistent" type="boolean" column="ver_loesch_jn"/>
        <property name="comment" type="string" column="ver_kommentar"/>

        <set name="cellGroups" lazy="true" inverse="true">
            <key>
                <column name="arb_lfdnr"/>
                <column name="ver_nr"/>
            </key>
            <one-to-many class="CellGroupImpl"/>
        </set>
        <many-to-one name="workspace" class="WorkspaceImpl" column="arb_lfdnr"/>
    </class>
</hibernate-mapping>


I don't have this problem with classes that have no composite ids.

Is this not possible with composite ids/keys???

Thanks for any help in advance!

Regards,
Oliver



Hibernate version:

Mapping documents:

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

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 1:52 pm 
Beginner
Beginner

Joined: Wed Dec 08, 2004 9:17 am
Posts: 25
Please ignore the "jdo" in the exception of the message above. Just replace it by "hibernate".
I did a bad job in "find and replace". ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 2:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
id is a reserved word in HQL - try replacing your key-property with name="id" with another name.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 4:54 am 
Beginner
Beginner

Joined: Wed Dec 08, 2004 9:17 am
Posts: 25
Hi Michael,

thanks for the prompt reply!

Unfortunately, refactoring the property "id" doesn't work either.

Refactoring from "id" to versionId" produces the following SQL from HQL:
Code:
main 18.01.2005 09:34:50.385 [DEBUG]    net.sf.hibernate.hql.QueryTranslator SQL: select versionimp0_.versionId as versionId, versionimp0_.workspaceId as workspac2_, versionimp0_.ver_nr as ver_nr, versionimp0_.arb_lfdnr as arb_lfdnr, versionimp0_.ver_name as ver_name, versionimp0_.ver_ang_zeit as ver_ang_6_, versionimp0_.ver_loesch_jn as ver_loes7_, versionimp0_.ver_kommentar as ver_komm8_ from dbo.funver versionimp0_ where (versionimp0_.versionId=? )and(versionimp0_.workspaceId=? ) 


Please note that the java class' property names of the composite id as well as their coresponding db column names are built into the SQL. Is that behaviour correct? Sybase responds with the statement that it doesn't know any column "versionId" or "workspaceId" (the java properties which represents the coposite key).
When I run a coresponding HQL query for a class with no composite id the java property which represent the id is NOT built into the SQL.

Any ideas???

Very confused....

Cheers,

Oliver


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 7:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Just guesssing but you have the key names as 'id' and you another property with the name 'id'. Did you change both?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 7:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Ugh - you don't have to map your propertys both in the composite-key element and as a property. Just key-property is enough, and specify the column names there.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 19, 2005 5:06 am 
Beginner
Beginner

Joined: Wed Dec 08, 2004 9:17 am
Posts: 25
Thanks guys!

Michael, your hint solved the problem with the workspace and the versions collection. Removing the extra property elements for the key properties and putting the type and column information into the key-property elements worked great.

But what should I do if I have a mapping like the following? If I remove the property elements for workspaceId, versionId and name and put their type and column info as attributes into the coresponding key-property elements I have the problem that I see no way of specifing insert="false" and update="false" attributes for the arb_lfdnr column which I have to since Hibernate tells me to do so for repeated columns in mappings (insert and update attributes do not exist for key-property elements or column elements).

Code:
<hibernate-mapping schema="dbo" package="de.vodafone.rnp.core.business.persistence.hibernate">
    <class name="CellGroupImpl" table="funzgr" proxy="CellGroupImpl" lazy="true">
        <composite-id>
            <key-property name="workspaceId"/>
            <key-property name="versionId"/>
            <key-property name="name"/>
        </composite-id>
        <property name="workspaceId" type="integer" column="arb_lfdnr" insert="false" update="false"/>
        <property name="versionId" type="integer" column="ver_nr" insert="false" update="false"/>
        <property name="name" type="string" column="zgr_id"/>
       
        <set name="cells" table="vsto_funzgm" lazy="true" inverse="true">
            <key>
                <column name="arb_lfdnr_1"/>
                <column name="ver_nr_1"/>
                <column name="zgr_id"/>
            </key>
            <many-to-many class="CellImpl">
                <column name="arb_lfdnr_2"/>
                <column name="ver_nr_2"/>
                <column name="nls_id"/>
                <column name="sta_id"/>
                <column name="sta_loc"/>
                <column name="alt_nr"/>
                <column name="fan_lfdnr"/>
                <column name="zel_id"/>
            </many-to-many>
        </set>
        <many-to-one name="version" class="VersionImpl">
            <column name="arb_lfdnr"/>
            <column name="ver_nr"/>
        </many-to-one>
    </class>
</hibernate-mapping>


Only half confused,

Oliver


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