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