-->
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.  [ 6 posts ] 
Author Message
 Post subject: HQL - product and sum in select
PostPosted: Mon May 31, 2004 6:41 am 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
I wrote the following query:

list = session.find("select SUM(postavka.kolicina*normativ.normativ), material.id " +
"from IzdaniRacun racun " +
"inner join racun.postavke postavka, " +
"NormativIzdRac normativ " +
"inner join normativ.material material " +
"where postavka = normativ.postavkaIzdRac " +
"group by material.id");

The generated SQL query is correct, but I get error "No such column x2_0_". Of course there is no column x2_0_ in generated query, but why Hibernate needs it?

Thank you for your help!

Marko

Code:
--------------------------------------------------------------------------------------
INFO  - Hibernate 2.1.2
INFO  - loaded properties from resource hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.jdbc.batch_size=0, hibernate.proxool.pool_alias=pool1, hibernate.connection.username=sa, hibernate.connection.password=marko, hibernate.connection.pool_size=1}
INFO  - using java.io streams to persist binary types
INFO  - using CGLIB reflection optimizer
INFO  - configuring from resource: /hibernate.cfg.xml
INFO  - Configuration resource: /hibernate.cfg.xml
INFO  - Mapping resource: si/marko/hibernate/Kategorija.hbm
INFO  - Mapping class: si.marko.hibernate.Kategorija -> kategorija
INFO  - Mapping resource: si/marko/hibernate/Artikel.hbm
INFO  - Mapping class: si.marko.hibernate.Artikel -> artikel
INFO  - Mapping resource: si/marko/hibernate/Inventura.hbm
INFO  - Mapping class: si.marko.hibernate.Inventura -> inventura
INFO  - Mapping resource: si/marko/hibernate/Material.hbm
INFO  - Mapping class: si.marko.hibernate.Material -> material
INFO  - Mapping resource: si/marko/hibernate/Normativ.hbm
INFO  - Mapping class: si.marko.hibernate.Normativ -> normativ
INFO  - Mapping resource: si/marko/hibernate/IzdaniRacun.hbm
INFO  - Mapping class: si.marko.hibernate.IzdaniRacun -> izdani_racun
INFO  - Mapping collection: si.marko.hibernate.IzdaniRacun.kategorija -> izdani_racun_kategorija
INFO  - Mapping resource: si/marko/hibernate/PostavkaIzdRac.hbm
INFO  - Mapping class: si.marko.hibernate.PostavkaIzdRac -> postavka_izd_rac
INFO  - Mapping subclass: si.marko.hibernate.PostavkaIzdRacObic -> postavka_izd_rac
INFO  - Mapping subclass: si.marko.hibernate.PostavkaIzdRacArt -> postavka_izd_rac
INFO  - Mapping resource: si/marko/hibernate/PrejetiRacun.hbm
INFO  - Mapping class: si.marko.hibernate.PrejetiRacun -> prejeti_racun
INFO  - Mapping collection: si.marko.hibernate.PrejetiRacun.kategorija -> prejeti_racun_kategorija
INFO  - Mapping resource: si/marko/hibernate/PostavkaPrejRac.hbm
INFO  - Mapping class: si.marko.hibernate.PostavkaPrejRac -> postavka_prej_rac
INFO  - Mapping resource: si/marko/hibernate/NormativIzdRac.hbm
INFO  - Mapping class: si.marko.hibernate.NormativIzdRac -> normativ_izd__rac
INFO  - Mapping resource: si/marko/hibernate/Partner.hbm
INFO  - Mapping class: si.marko.hibernate.Partner -> partner
INFO  - Configured SessionFactory: null
INFO  - processing one-to-many association mappings
INFO  - Mapping collection: si.marko.hibernate.IzdaniRacun.postavke -> postavka_izd_rac
INFO  - Mapping collection: si.marko.hibernate.PrejetiRacun.postavke -> postavka_prej_rac
INFO  - processing one-to-one association property references
INFO  - processing foreign key constraints
INFO  - Using dialect: net.sf.hibernate.dialect.SQLServerDialect
INFO  - Maximim outer join fetch depth: 1
INFO  - Use outer join fetching: true
INFO  - C3P0 using driver: com.newatlanta.jturbo.driver.DataSource at URL: jdbc:JTurbo://marko:1433/kovinoplastika
INFO  - Connection properties: {user=sa, password=marko}
INFO  - Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory
INFO  - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
INFO  - Use scrollable result sets: true
INFO  - Use JDBC3 getGeneratedKeys(): false
INFO  - Optimize cache for minimal puts: false
INFO  - echoing all SQL to stdout
INFO  - Query language substitutions: {no='N', true=1, yes='Y', false=0}
INFO  - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
INFO  - instantiating and configuring caches
INFO  - building session factory
INFO  - no JNDI name configured
INFO  - starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
INFO  - starting query cache at region: net.sf.hibernate.cache.QueryCache
Hibernate: select SUM(postavke1_.kolicina*normativiz2_.normativ) as x0_0_, material3_.ID as x1_0_ from izdani_racun izdaniracu0_ inner join postavka_izd_rac postavke1_ on izdaniracu0_.ID=postavke1_.izd_racID, normativ_izd__rac normativiz2_ inner join material material3_ on normativiz2_.materialID=material3_.ID where (postavke1_.ID=normativiz2_.postavkaID ) group by  material3_.ID
WARN  - SQL Error: 0, SQLState: null
ERROR - [JTurbo 3.0.2 JDBC 3.0 Driver]: No such column x2_0_
WARN  - SQL Error: 0, SQLState: null
ERROR - [JTurbo 3.0.2 JDBC 3.0 Driver]: No such column x2_0_
ERROR - Could not execute query
java.sql.SQLException: [JTurbo 3.0.2 JDBC 3.0 Driver]: No such column x2_0_
   at com.newatlanta.jturbo.driver.m.findColumn(m.java)
   at com.newatlanta.jturbo.driver.m.getString(m.java)
   at com.mchange.v2.c3p0.impl.C3P0ResultSet.getString(C3P0ResultSet.java:183)
   at net.sf.hibernate.type.StringType.get(StringType.java:18)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
   at net.sf.hibernate.hql.QueryTranslator.getResultColumnOrRow(QueryTranslator.java:985)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:222)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.doList(Loader.java:950)
   at net.sf.hibernate.loader.Loader.list(Loader.java:941)
   at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1483)
   at si.marko.hibernate.Test.main(Test.java:444)
net.sf.hibernate.JDBCException: Could not execute query
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1515)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1483)
   at si.marko.hibernate.Test.main(Test.java:444)
Caused by: java.sql.SQLException: [JTurbo 3.0.2 JDBC 3.0 Driver]: No such column x2_0_
   at com.newatlanta.jturbo.driver.m.findColumn(m.java)
   at com.newatlanta.jturbo.driver.m.getString(m.java)
   at com.mchange.v2.c3p0.impl.C3P0ResultSet.getString(C3P0ResultSet.java:183)
   at net.sf.hibernate.type.StringType.get(StringType.java:18)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
   at net.sf.hibernate.hql.QueryTranslator.getResultColumnOrRow(QueryTranslator.java:985)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:222)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.doList(Loader.java:950)
   at net.sf.hibernate.loader.Loader.list(Loader.java:941)
   at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
   ... 3 more


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 12:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
arithmetic expressions are not (yet) supported in the SELECT clause.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 2:55 pm 
Newbie

Joined: Mon May 31, 2004 6:26 am
Posts: 18
Than you for your help.

Marko


Top
 Profile  
 
 Post subject: Any thoughts on timing?
PostPosted: Wed Jun 09, 2004 3:43 pm 
Regular
Regular

Joined: Fri Sep 12, 2003 12:40 pm
Posts: 65
Gavin, I could not find a JIRA posting about arithmetic expressions in the select statement of HQL.

Do you know when (yet) is? Has someone begun working on it?

I started looking at the ...hql.PathExpressionParser, ...hql.SelectParser, and ...hql.QueryTranslator and I'm not sure of where best to implement this functionality--it looks like this code could be in flux. Do you have a suggestion?

_________________
- Brian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 7:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Hibernate 3.x will have a new parser which will make this much easier to provide.


Top
 Profile  
 
 Post subject: Native SQL Queries?
PostPosted: Thu Jun 10, 2004 2:27 pm 
Newbie

Joined: Thu Jun 10, 2004 2:24 pm
Posts: 3
I am having this same problem. But, I was under the understanding that this could be done through the native sql feature of hibrenate (Session.createSQLQuery()). Yet, it doesn't work, so I'm inclined to say "no." Can someone confirm this?


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