Hibernate version:3.2.6
MSSQLServer 2005
org.hibernate.dialect.SQLServerDialect
org.apache.commons.dbcp.BasicDataSource
com.microsoft.sqlserver.jdbc.SQLServerDriver
I'm seeing this error when I try to use a discriminator with a formula.
"NullableType:main - could not read column value from result set: null; The column name null is not valid"
In this case, I'm trying to use a discriminator value from another table with a select. Does anyone have any insight into what is wrong. I've tried several different variations of using formulas for discriminators based on examples I've found, but they all lead to this same error.
Thanks
Here is the discriminator definition:
<discriminator formula="(select mc.couponTypeInteger from phaAPI.MasterCoupon mc where mc.id = masterCouponId)"/>
Here are two pertainant XML files:
First the class that I'm trying to set up inheritance for:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="COUPON" name="phaAPI.Coupon" discriminator-value="0">
<id name="id" column="COUPON_ID">
<generator class="native"/>
</id>
<discriminator formula="(select mc.couponTypeInteger from phaAPI.MasterCoupon mc where mc.id = masterCouponId)"/>
<property name="masterCouponId" column="MASTER_COUPON_ID" />
...
<subclass name="phaAPI.GuestCoupon" discriminator-value="1">
</subclass>
<subclass name="phaAPI.FreeShipCoupon" discriminator-value="2">
</subclass>
</class>
</hibernate-mapping>
And the class with the discriminator value:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="MASTER_COUPON" name="phaAPI.MasterCoupon" >
<id name="id" column="MASTER_COUPON_ID">
<generator class="native"/>
</id>
<property name="couponTypeInteger" column="COUPON_TYPE" />
...
</class>
</hibernate-mapping>
And finally the detailed log output:
17:10:10,737 DEBUG SessionImpl:main - opened session at timestamp: 12169446107
17:10:10,737 DEBUG SessionImpl:main - opened session at timestamp: 12169446107
17:10:10,737 DEBUG JDBCTransaction:main - begin
17:10:10,737 DEBUG JDBCTransaction:main - begin
17:10:10,737 DEBUG ConnectionManager:main - opening JDBC connection
17:10:10,737 DEBUG ConnectionManager:main - opening JDBC connection
17:10:10,737 DEBUG JDBCTransaction:main - current autocommit status: true
17:10:10,737 DEBUG JDBCTransaction:main - current autocommit status: true
17:10:10,737 DEBUG JDBCTransaction:main - disabling autocommit
17:10:10,737 DEBUG JDBCTransaction:main - disabling autocommit
17:10:10,737 DEBUG AbstractBatcher:main - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
17:10:10,737 DEBUG AbstractBatcher:main - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
17:10:10,737 DEBUG AbstractBatcher:main - SELECT [COUPON_ID], [MASTER_COUPON_ID], [MEM_ID], [COUPON_NUMBER], [ACTIVE], [AMOUNT], [QUANTITY], [EXPIRATION_DATE], [CURRENCY_CDE], [INITIAL_AMOUNT], [RETAIL_VALUE], [REDEEMED], [CREATE_DATE], [MODIFIED_DATE] FROM [COUPON] WITH (NOLOCK) WHERE COUPON_NUMBER = ?
17:10:10,737 DEBUG AbstractBatcher:main - SELECT [COUPON_ID], [MASTER_COUPON_ID], [MEM_ID], [COUPON_NUMBER], [ACTIVE], [AMOUNT], [QUANTITY], [EXPIRATION_DATE], [CURRENCY_CDE], [INITIAL_AMOUNT], [RETAIL_VALUE], [REDEEMED], [CREATE_DATE], [MODIFIED_DATE] FROM [COUPON] WITH (NOLOCK) WHERE COUPON_NUMBER = ?
17:10:10,737 DEBUG Loader:main - bindNamedParameters() C680-38-1063-715 -> number [1]
17:10:10,737 DEBUG Loader:main - bindNamedParameters() C680-38-1063-715 -> number [1]
17:10:10,737 DEBUG AbstractBatcher:main - about to open ResultSet (open ResultSets: 0, globally: 0)
17:10:10,737 DEBUG AbstractBatcher:main - about to open ResultSet (open ResultSets: 0, globally: 0)
17:10:10,737 DEBUG Loader:main - result row: EntityKey[phaAPI.Coupon#76491]
17:10:10,737 DEBUG Loader:main - result row: EntityKey[phaAPI.Coupon#76491]
17:10:10,753 INFO NullableType:main - could not read column value from result set: null; The column name null is not valid.
17:10:10,753 INFO NullableType:main - could not read column value from result set: null; The column name null is not valid.
17:10:10,753 DEBUG AbstractBatcher:main - about to close ResultSet (open ResultSets: 1, globally: 1)
17:10:10,753 DEBUG AbstractBatcher:main - about to close ResultSet (open ResultSets: 1, globally: 1)
17:10:10,753 DEBUG AbstractBatcher:main - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
17:10:10,753 DEBUG AbstractBatcher:main - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
17:10:10,753 DEBUG JDBCExceptionReporter:main - could not execute query [SELECT [COUPON_ID], [MASTER_COUPON_ID], [MEM_ID], [COUPON_NUMBER], [ACTIVE], [AMOUNT], [QUANTITY], [EXPIRATION_DATE], [CURRENCY_CDE], [INITIAL_AMOUNT], [RETAIL_VALUE], [REDEEMED], [CREATE_DATE], [MODIFIED_DATE] FROM [COUPON] WITH (NOLOCK) WHERE COUPON_NUMBER = ?]
com.microsoft.sqlserver.jdbc.SQLServerException: The column name null is not valid.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.findColumn(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getString(Unknown Source)
at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:216)
at org.hibernate.type.StringType.get(StringType.java:18)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189)
at org.hibernate.loader.Loader.getInstanceClass(Loader.java:1442)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1284)
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:2213)
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 phaAPI.DbObjectDAOImpl.getDbObjects(DbObjectDAOImpl.java:289)
at phaAPI.DbObject.getDbObjects(DbObject.java:573)
at phaAPI.DbObject.getDbObjects(DbObject.java:529)
at phaAPI.Coupon.getCouponByNumber(Coupon.java:3110)
at phaAPI.Coupon.getCouponByNumber(Coupon.java:3089)
at test.TestCases.MasterCoupon.runTest(MasterCoupon.java:131)
at test.TestHarness.runTestCases(TestHarness.java:318)
at test.TestHarness.main(TestHarness.java:197)
17:10:10,753 DEBUG JDBCExceptionReporter:main - could not execute query [SELECT [COUPON_ID], [MASTER_COUPON_ID], [MEM_ID], [COUPON_NUMBER], [ACTIVE], [AMOUNT], [QUANTITY], [EXPIRATION_DATE], [CURRENCY_CDE], [INITIAL_AMOUNT], [RETAIL_VALUE], [REDEEMED], [CREATE_DATE], [MODIFIED_DATE] FROM [COUPON] WITH (NOLOCK) WHERE COUPON_NUMBER = ?]
com.microsoft.sqlserver.jdbc.SQLServerException: The column name null is not valid.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.findColumn(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getString(Unknown Source)
at org.apache.commons.dbcp.DelegatingResultSet.getString(DelegatingResultSet.java:216)
at org.hibernate.type.StringType.get(StringType.java:18)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:163)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:189)
at org.hibernate.loader.Loader.getInstanceClass(Loader.java:1442)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1284)
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:2213)
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 phaAPI.DbObjectDAOImpl.getDbObjects(DbObjectDAOImpl.java:289)
at phaAPI.DbObject.getDbObjects(DbObject.java:573)
at phaAPI.DbObject.getDbObjects(DbObject.java:529)
at phaAPI.Coupon.getCouponByNumber(Coupon.java:3110)
at phaAPI.Coupon.getCouponByNumber(Coupon.java:3089)
at test.TestCases.MasterCoupon.runTest(MasterCoupon.java:131)
at test.TestHarness.runTestCases(TestHarness.java:318)
at test.TestHarness.main(TestHarness.java:197)
17:10:10,753 WARN JDBCExceptionReporter:main - SQL Error: 0, SQLState: S1093
17:10:10,753 WARN JDBCExceptionReporter:main - SQL Error: 0, SQLState: S1093
17:10:10,753 ERROR JDBCExceptionReporter:main - The column name null is not valid.
17:10:10,753 ERROR JDBCExceptionReporter:main - The column name null is not valid.
17:10:10,753 DEBUG JDBCTransaction:main - rollback
17:10:10,753 DEBUG JDBCTransaction:main - rollback
17:10:10,753 DEBUG JDBCTransaction:main - re-enabling autocommit
17:10:10,753 DEBUG JDBCTransaction:main - re-enabling autocommit
17:10:10,753 DEBUG JDBCTransaction:main - rolled back JDBC Connection
17:10:10,753 DEBUG JDBCTransaction:main - rolled back JDBC Connection
|