java.sql.SQLException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • (from http://forum.hibernate.org/viewtopic.php?p=2190300#2190300) Problem: Hibernate pukes (see stack trace) because of the brackets [] around a column name (Site Type (yes, there is a space in the column name)) in the WHERE clause of a SET mapping. <set name="tableSubAs" inverse="true" where="[Site Type]=1" > How do I get around this? I've tried backticks ` and apostrophes ' but these don't work either. Detailed description: I'm working with a legacy database which has a table (TableA) with a column whose name includes a space. The column name is "Site Type". It just so happens that this column is a discriminator value for subclasses to TableA (like TableSubA). In my mapping document, I have a property mapping for this column that works just fine: <property name="siteType" type="byte" column="[Site Type]" length="3" /> Notice the brackets [ ] used around the column name b/c of the space. However, another table (TableB) contains a set of TableSubA's (the subclass). In order for the set to only contain the subclass, I need to use the WHERE clause in the set mapping (see FAQ http://www.hibernate.org/117.html#A13) to specify the included elements should have a Site Type of 1. <set name="tableSubAs" inverse="true" where="[Site Type]=1" > <key> <column name="id" /> </key> <one-to-many class="foo.TableSubA" /> </set> Stack trace: org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [null] in task 'HibernateAccessor'; nested exception is: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source) at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:83) at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:794) at net.sf.hibernate.loader.Loader.doQuery(Loader.java:188) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:909) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:884) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:80) at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284) at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3133) at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:331) at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3007) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:137) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:830) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:850) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49) at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:420) at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2044) at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1918) at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1847) at org.springframework.orm.hibernate.HibernateTemplate$3.doInHibernate(HibernateTemplate.java:221) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:147) at org.springframework.orm.hibernate.HibernateTemplate.load(HibernateTemplate.java:219) at dars.clientmap.dao.hibernate.StateDaoHibernate.loadState(StateDaoHibernate.java:21) at dars.clientmap.dao.AbstractStateDaoTest.testLoadStateRealState(AbstractStateDaoTest.java:31) 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:397) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:281) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:173) org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [null] in task 'HibernateAccessor'; nested exception is: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [null] in task 'HibernateAccessor'; nested exception is: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [null] in task 'HibernateAccessor'; nested exception is: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source) at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:83) at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:794) at net.sf.hibernate.loader.Loader.doQuery(Loader.java:188) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:909) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:884) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:80) at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284) at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3133) at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:331) at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3007) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:137) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:830) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:850) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49) at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:420) at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2044) at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1918) at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1847) at org.springframework.orm.hibernate.HibernateTemplate$3.doInHibernate(HibernateTemplate.java:221) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:147) at org.springframework.orm.hibernate.HibernateTemplate.load(HibernateTemplate.java:219) at dars.clientmap.dao.hibernate.StateDaoHibernate.loadState(StateDaoHibernate.java:21) at dars.clientmap.dao.AbstractStateDaoTest.testLoadStateRealState(AbstractStateDaoTest.java:31) 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:397) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:281) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:173)
    via by Jon Chase,
  • (from http://forum.hibernate.org/viewtopic.php?p=2190300#2190300) Problem: Hibernate pukes (see stack trace) because of the brackets [] around a column name (Site Type (yes, there is a space in the column name)) in the WHERE clause of a SET mapping. <set name="tableSubAs" inverse="true" where="[Site Type]=1" > How do I get around this? I've tried backticks ` and apostrophes ' but these don't work either. Detailed description: I'm working with a legacy database which has a table (TableA) with a column whose name includes a space. The column name is "Site Type". It just so happens that this column is a discriminator value for subclasses to TableA (like TableSubA). In my mapping document, I have a property mapping for this column that works just fine: <property name="siteType" type="byte" column="[Site Type]" length="3" /> Notice the brackets [ ] used around the column name b/c of the space. However, another table (TableB) contains a set of TableSubA's (the subclass). In order for the set to only contain the subclass, I need to use the WHERE clause in the set mapping (see FAQ http://www.hibernate.org/117.html#A13) to specify the included elements should have a Site Type of 1. <set name="tableSubAs" inverse="true" where="[Site Type]=1" > <key> <column name="id" /> </key> <one-to-many class="foo.TableSubA" /> </set> Stack trace: org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [null] in task 'HibernateAccessor'; nested exception is: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source) at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:83) at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:794) at net.sf.hibernate.loader.Loader.doQuery(Loader.java:188) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:909) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:884) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:80) at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284) at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3133) at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:331) at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3007) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:137) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:830) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:850) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49) at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:420) at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2044) at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1918) at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1847) at org.springframework.orm.hibernate.HibernateTemplate$3.doInHibernate(HibernateTemplate.java:221) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:147) at org.springframework.orm.hibernate.HibernateTemplate.load(HibernateTemplate.java:219) at dars.clientmap.dao.hibernate.StateDaoHibernate.loadState(StateDaoHibernate.java:21) at dars.clientmap.dao.AbstractStateDaoTest.testLoadStateRealState(AbstractStateDaoTest.java:31) 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:397) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:281) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:173) org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [null] in task 'HibernateAccessor'; nested exception is: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [null] in task 'HibernateAccessor'; nested exception is: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [null] in task 'HibernateAccessor'; nested exception is: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source) at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:83) at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:794) at net.sf.hibernate.loader.Loader.doQuery(Loader.java:188) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:909) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:884) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:80) at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284) at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3133) at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:331) at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3007) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:137) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:830) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:850) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49) at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:420) at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2044) at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1918) at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1847) at org.springframework.orm.hibernate.HibernateTemplate$3.doInHibernate(HibernateTemplate.java:221) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:147) at org.springframework.orm.hibernate.HibernateTemplate.load(HibernateTemplate.java:219) at dars.clientmap.dao.hibernate.StateDaoHibernate.loadState(StateDaoHibernate.java:21) at dars.clientmap.dao.AbstractStateDaoTest.testLoadStateRealState(AbstractStateDaoTest.java:31) 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:397) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:281) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:173)
    via by Jon Chase,
  • If you have in your mappings set fetch="join" and order-by="" for child collection like in this mapping: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping package="test.model"> <class name="Cat" table="CAT"> <id name="catId" column="CAT_ID" type="java.lang.Integer"> <generator class="native"/> </id> <property name="name" column="NAME" type="java.lang.String" /> <property name="color" column="COLOR" type="java.lang.String" /> <property name="gender" column="GENDER" type="java.lang.String" /> <set name="kittens" fetch="join" cascade="all-delete-orphan" inverse="true" order-by="name" > <key column="MOTHER_ID"/> <one-to-many class="Cat"/> </set> </class> </hibernate-mapping> adding Projection to criteria will have in a result incorrect query generated and execution will fail, like that: Hibernate: select count(*) as y0_ from CAT this_ left outer join CAT kittens2_ on this_.CAT_ID=kittens2_.MOTHER_ID where this_.COLOR=? order by kittens2_.name 14:12:45,163 ERROR JDBCExceptionReporter:72 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Column name 'kittens2_.NAME' is invalid in the ORDER BY clause because it is not contained in an aggregate function and there is no GROUP BY clause. org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:1596) at org.hibernate.loader.Loader.list(Loader.java:1577) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1322) at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300) at test.test.Test.test(Test.java:62) at test.test.Test.main(Test.java:79) Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Column name 'kittens2_.NAME' is invalid in the ORDER BY clause because it is not contained in an aggregate function and there is no GROUP BY clause. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120) at org.hibernate.loader.Loader.getResultSet(Loader.java:1272) at org.hibernate.loader.Loader.doQuery(Loader.java:391) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218) at org.hibernate.loader.Loader.doList(Loader.java:1593) ... 6 more Source code for criteria is: List results = session.createCriteria(Cat.class) .setProjection( Projections.rowCount() ) .add( Restrictions.eq("color", "BLACK") ) .list(); If you remove fetch="join" everything works just fine. Even if you will use subcriteria with child attributes. Changes in any other attributes have no effect.
    via by Vasyl Zhabko,
  • If you have in your mappings set fetch="join" and order-by="" for child collection like in this mapping: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping package="test.model"> <class name="Cat" table="CAT"> <id name="catId" column="CAT_ID" type="java.lang.Integer"> <generator class="native"/> </id> <property name="name" column="NAME" type="java.lang.String" /> <property name="color" column="COLOR" type="java.lang.String" /> <property name="gender" column="GENDER" type="java.lang.String" /> <set name="kittens" fetch="join" cascade="all-delete-orphan" inverse="true" order-by="name" > <key column="MOTHER_ID"/> <one-to-many class="Cat"/> </set> </class> </hibernate-mapping> adding Projection to criteria will have in a result incorrect query generated and execution will fail, like that: Hibernate: select count(*) as y0_ from CAT this_ left outer join CAT kittens2_ on this_.CAT_ID=kittens2_.MOTHER_ID where this_.COLOR=? order by kittens2_.name 14:12:45,163 ERROR JDBCExceptionReporter:72 - [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Column name 'kittens2_.NAME' is invalid in the ORDER BY clause because it is not contained in an aggregate function and there is no GROUP BY clause. org.hibernate.exception.GenericJDBCException: could not execute query at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.loader.Loader.doList(Loader.java:1596) at org.hibernate.loader.Loader.list(Loader.java:1577) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:111) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1322) at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300) at test.test.Test.test(Test.java:62) at test.test.Test.main(Test.java:79) Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Column name 'kittens2_.NAME' is invalid in the ORDER BY clause because it is not contained in an aggregate function and there is no GROUP BY clause. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:120) at org.hibernate.loader.Loader.getResultSet(Loader.java:1272) at org.hibernate.loader.Loader.doQuery(Loader.java:391) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218) at org.hibernate.loader.Loader.doList(Loader.java:1593) ... 6 more Source code for criteria is: List results = session.createCriteria(Cat.class) .setProjection( Projections.rowCount() ) .add( Restrictions.eq("color", "BLACK") ) .list(); If you remove fetch="join" everything works just fine. Even if you will use subcriteria with child attributes. Changes in any other attributes have no effect.
    via by Vasyl Zhabko,
  • Hibernate-Criteria: Group by column alias
    via by Emili Calonge,
  • org hibernate exception GenericJDBCException
    via by vikram sisodia,
  • JDBC | SQL Server connection error
    via Stack Overflow by MMRUser
    ,
    • java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid column name 'Site clients0_.Type'. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source) at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source) at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source) at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source) at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source) at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:83) at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:794) at net.sf.hibernate.loader.Loader.doQuery(Loader.java:188) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:909) at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:884) at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:80) at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284) at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3133) at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:331) at net.sf.hibernate.impl.SessionImpl.initializeNonLazyCollections(SessionImpl.java:3007) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:137) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:830) at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:850) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:57) at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:49) at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:420) at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2044) at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1918) at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1847) at org.springframework.orm.hibernate.HibernateTemplate$3.doInHibernate(HibernateTemplate.java:221) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:147) at org.springframework.orm.hibernate.HibernateTemplate.load(HibernateTemplate.java:219) at dars.clientmap.dao.hibernate.StateDaoHibernate.loadState(StateDaoHibernate.java:21) at dars.clientmap.dao.AbstractStateDaoTest.testLoadStateRealState(AbstractStateDaoTest.java:31) 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:397) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:281) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:173)

    Users with the same issue

    rp
    1 times, last one,
    Unknown visitor1 times, last one,