I have a field "dec" with the following annotation:
Code:
@Column(name = "`DEC`", nullable = false)
When I perform
Code:
session.createSQLQuery(s);
query.addEntity(Kic.class);
query.list();
I get
Code:
java.sql.SQLException: Column not found: "DEC"
I'd think that since Hibernate knows about the quoting, it should be able to DTRT when marshalling the results. Bug?
Hibernate version: 3.2.3
Mapping documents:Code:
Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class StellarObject {
@Id
@Column(nullable = false)
protected int keplerId;
@Column(nullable = false)
protected double ra;
@Column(name = "`DEC`", nullable = false)
protected double dec;
...
Code:
@Entity
@Table(name = "CM_KIC")
public class Kic extends StellarObject {
...
}
Code between sessionFactory.openSession() and session.close():Code:
String s = "select * from CM_KIC where...";
SQLQuery query = dbService.getSession().createSQLQuery(s);
query.addEntity(Kic.class);
List<Kic> results = (List<Kic>) query.list(); <- Exception here
Name and version of the database you are using:Oracle 10.
Log, SQL, and full stack trace:Code:
2007-06-12 09:50:23,804 DEBUG [main:SessionImpl.<init>] opened session at timestamp: 11816670238
2007-06-12 09:50:23,817 DEBUG [main:QueryPlanCache.getNativeSQLQueryPlan] unable to locate native-sql query plan in cache; generating (select * from CM_KIC kic where kic.KEPLER_ID > 1 and kic.KEPLER_ID < 5)
2007-06-12 09:50:23,821 DEBUG [main:SQLCustomQuery.<init>] starting processing of sql query [select * from CM_KIC kic where kic.KEPLER_ID > 1 and kic.KEPLER_ID < 5]
2007-06-12 09:50:23,827 DEBUG [main:SQLQueryReturnProcessor.addPersister] mapping alias [Kic] to entity-suffix [0_]
2007-06-12 09:50:23,833 DEBUG [main:SessionImpl.listCustomQuery] SQL query: select * from CM_KIC kic where kic.KEPLER_ID > 1 and kic.KEPLER_ID < 5
2007-06-12 09:50:23,839 DEBUG [main:AbstractBatcher.logOpenPreparedStatement] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2007-06-12 09:50:23,839 DEBUG [main:ConnectionManager.openConnection] opening JDBC connection
2007-06-12 09:50:23,839 DEBUG [main:DriverManagerConnectionProvider.getConnection] total checked-out connections: 0
2007-06-12 09:50:23,839 DEBUG [main:DriverManagerConnectionProvider.getConnection] using pooled JDBC connection, pool size: 0
2007-06-12 09:50:23,840 DEBUG [main:AbstractBatcher.log]
/* dynamic native SQL query */ select
top ? *
from
CM_KIC kic
where
kic.KEPLER_ID > 1
and kic.KEPLER_ID < 5
Hibernate:
/* dynamic native SQL query */ select
top ? *
from
CM_KIC kic
where
kic.KEPLER_ID > 1
and kic.KEPLER_ID < 5
2007-06-12 09:50:23,840 DEBUG [main:AbstractBatcher.getPreparedStatement] preparing statement
2007-06-12 09:50:23,842 DEBUG [main:AbstractBatcher.logOpenResults] about to open ResultSet (open ResultSets: 0, globally: 0)
2007-06-12 09:50:23,843 DEBUG [main:Loader.doQuery] processing result set
2007-06-12 09:50:23,843 DEBUG [main:Loader.doQuery] result set row: 0
2007-06-12 09:50:23,843 DEBUG [main:NullableType.nullSafeGet] returning '2' as column: KEPLER_ID
2007-06-12 09:50:23,844 DEBUG [main:Loader.getRow] result row: EntityKey[gov.nasa.kepler.hibernate.cm.Kic#2]
2007-06-12 09:50:23,844 DEBUG [main:Loader.loadFromResultSet] Initializing object from ResultSet: [gov.nasa.kepler.hibernate.cm.Kic#2]
2007-06-12 09:50:23,846 DEBUG [main:AbstractEntityPersister.hydrate] Hydrating entity: [gov.nasa.kepler.hibernate.cm.Kic#2]
2007-06-12 09:50:23,847 INFO [main:NullableType.nullSafeGet] could not read column value from result set: "DEC"; Column not found: "DEC"
2007-06-12 09:50:23,847 DEBUG [main:AbstractBatcher.logCloseResults] about to close ResultSet (open ResultSets: 1, globally: 1)
2007-06-12 09:50:23,848 DEBUG [main:AbstractBatcher.logClosePreparedStatement] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2007-06-12 09:50:23,848 DEBUG [main:AbstractBatcher.closePreparedStatement] closing statement
2007-06-12 09:50:23,851 DEBUG [main:JDBCExceptionReporter.logExceptions] could not execute query [select * from CM_KIC kic where kic.KEPLER_ID > 1 and kic.KEPLER_ID < 5]
java.sql.SQLException: Column not found: "DEC"
at org.hsqldb.jdbc.Util.sqlException(Util.java:61)
at org.hsqldb.jdbc.Util.sqlException(Util.java:70)
at org.hsqldb.jdbc.jdbcResultSet.findColumn(jdbcResultSet.java:1671)
at org.hsqldb.jdbc.jdbcResultSet.getDouble(jdbcResultSet.java:1159)
at org.hibernate.type.DoubleType.get(DoubleType.java:22)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:154)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2096)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1380)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1308)
at org.hibernate.loader.Loader.getRow(Loader.java:1206)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at gov.nasa.kepler.hibernate.cm.KicCrud.retrieveKics(KicCrud.java:191)
at gov.nasa.kepler.hibernate.cm.KicCrudTest.testRetrieveKicsWithQuery(KicCrudTest.java:468)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
2007-06-12 09:50:23,854 WARN [main:JDBCExceptionReporter.logExceptions] SQL Error: -28, SQLState: S0022
2007-06-12 09:50:23,854 ERROR [main:JDBCExceptionReporter.logExceptions] Column not found: "DEC"
2007-06-12 09:50:23,855 DEBUG [main:JDBCContext.afterNontransactionalQuery] after autocommit
2007-06-12 09:50:23,855 DEBUG [main:ConnectionManager.aggressiveRelease] aggressively releasing JDBC connection
2007-06-12 09:50:23,855 DEBUG [main:ConnectionManager.closeConnection] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2007-06-12 09:50:23,855 DEBUG [main:DriverManagerConnectionProvider.closeConnection] returning connection to pool, pool size: 1
2007-06-12 09:50:23,870 DEBUG [main:SessionImpl.close] closing session
2007-06-12 09:50:23,870 DEBUG [main:ConnectionManager.cleanup] connection already null in cleanup : no action