-->
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: use composite object in query
PostPosted: Tue Sep 28, 2004 8:56 am 
Newbie

Joined: Tue Sep 28, 2004 8:46 am
Posts: 5
Hibernate version:
2.1.6


Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
<class
name="com.gudrun.gdp3000.centralfile.domain.Usage"
table="USAGE"
proxy="com.gudrun.gdp3000.centralfile.domain.Usage"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
>

<id
name="id"
column="id"
type="java.lang.Integer"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Usage.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<property
name="date"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="DATE"
/>

<property
name="type"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="TYPE"
/>

<many-to-one
name="centralFile"
class="com.gudrun.gdp3000.centralfile.domain.CentralFile"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="CENTRAL_FILE_ID"
/>

<property
name="lastModificationDate"
type="java.sql.Timestamp"
update="true"
insert="true"
access="property"
column="LAST_MODIFICATION_DATE"
/>

<property
name="lastModificationUser"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="LAST_MODIFICATION_USER"
/>

<property name="amount"
type="com.gudrun.gdp3000.utils.MoneyValueCompositeUserType">
<column name="AMOUNT"/>
<column name="CURRENCY"/>
</property>

</class>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Iterator i = session.createQuery( "select usage.type,sum(usage.amount) from Usage usage group by usage.type") .list() .iterator();


Full stack trace of any exception that occurs:
org.springframework.orm.hibernate.HibernateQueryException: path expression ends in a composite value: usage0_.amount [select usage.type,sum(usage.amount) from com.gudrun.gdp3000.centralfile.domain.Usage usage group by usage.type]; nested exception is net.sf.hibernate.QueryException: path expression ends in a composite value: usage0_.amount [select usage.type,sum(usage.amount) from com.gudrun.gdp3000.centralfile.domain.Usage usage group by usage.type]
net.sf.hibernate.QueryException: path expression ends in a composite value: usage0_.amount [select usage.type,sum(usage.amount) from com.gudrun.gdp3000.centralfile.domain.Usage usage group by usage.type]
at net.sf.hibernate.hql.PathExpressionParser.getWhereColumn(PathExpressionParser.java:375)
at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:160)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114)
at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:294)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1562)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1533)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.gudrun.gdp3000.centralfile.dao.hibernate.UsageDAOImpl.getUsedTypesForPeriod(UsageDAOImpl.java:101)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:116)
at org.springframework.orm.hibernate.HibernateInterceptor.invoke(HibernateInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:152)
at $Proxy16.getUsedTypesForPeriod(Unknown Source)
at com.gudrun.gdp3000.centralfile.dao.hibernate.UsageTest.testGetUsedTypesForPeriod(UsageTest.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)



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: Tue Sep 28, 2004 10:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
do something like sum(usage.amount.xxx) where the xxx is the value you return in your getPropertyNames() implementation of your usertype


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 7:08 am 
Newbie

Joined: Tue Sep 28, 2004 8:46 am
Posts: 5
use of sum(usage.amount.amount)
where the second amount is the property of the composite class amount containing the required data
resulted in

org.springframework.jdbc.UncategorizedSQLException: (Hibernate operation): encountered SQLException [[GUDRUNSQL]The column prefix 'this.amount' does not match with a table name or alias name used in the query.]; nested exception is java.sql.SQLException: [GUDRUNSQL]The column prefix 'this.amount' does not match with a table name or alias name used in the query.
java.sql.SQLException: [GUDRUNSQL]The column prefix 'this.amount' does not match with a table name or alias name used in the query.
at com.inet.tds.a.a(Unknown Source)
at com.inet.tds.b.byte(Unknown Source)
at com.inet.tds.b.new(Unknown Source)
at com.inet.tds.b.executeQuery(Unknown Source)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.gudrun.gdp3000.centralfile.dao.hibernate.UsageDAOImpl$2.doInHibernate(UsageDAOImpl.java:124)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:176)
at com.gudrun.gdp3000.centralfile.dao.hibernate.UsageDAOImpl.getUsedTypesTest(UsageDAOImpl.java:111)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:116)
at org.springframework.orm.hibernate.HibernateInterceptor.invoke(HibernateInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:138)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:152)
at $Proxy16.getUsedTypesTest(Unknown Source)
at com.gudrun.gdp3000.centralfile.dao.hibernate.UsageTest.testGetUsedTypesTest(UsageTest.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 7:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
check the generated SQL, try to find the error.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 7:47 am 
Newbie

Joined: Tue Sep 28, 2004 8:46 am
Posts: 5
<property name="amount"
type="com.gudrun.gdp3000.utils.MoneyValueCompositeUserType">
<column name="AMOUNT"/>
<column name="CURRENCY"/>
</property>

no errors in sql I think because when I run the sql fetching usage.amount.currency it works fine,
however when I fetch the amount instead of the currency with
usage.amount.amount the exception occurs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 7:51 am 
Newbie

Joined: Tue Sep 28, 2004 8:46 am
Posts: 5
using sql

select this.type,this.amount.currency from Usage this

is ok

using sql

select this.type,this.amount.amount from Usage this

is not ok


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 8:03 am 
Newbie

Joined: Tue Sep 28, 2004 8:46 am
Posts: 5
its solved Michael
thanks for your effort

problem was that in the getPropertyNames I used "value"

so usage.amount.value works fine


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.