Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.1.2
Mapping documents:
Code:
<hibernate-mapping package="com.harris.netboss.common.schema">
<class name="InstanceProperty" table="instance_property">
<cache usage="read-write" />
<id name="id" column="id" type="long">
<generator class="native" />
</id>
<version name="version" column="version" type="long" />
<property name="name" column="name" type="string"
not-null="true" />
<property name="value"
type="com.harris.netboss.server.modelspace.CimValueType">
<column name="value" />
<column name="value_type" not-null="true" />
</property>
<set name="owners" table="iclass_to_iproperty" inverse="true"
cascade="save-update">
<cache usage="read-write" />
<key column="instance_property_id" />
<many-to-many class="InstanceClass"
column="instance_class_id" />
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Query q = session.createQuery("select count(*) from InstanceProperty as ip where ip.value = :namespacePath");
q.setParameter("namespacePath", namespacePath, Hibernate.custom(CimValueType.class));
return q.uniqueResult();
Full stack trace of any exception that occurs:Code:
org.springframework.jdbc.InvalidResultSetAccessException: Hibernate operation: could not execute query; invalid ResultSet access for SQL [select count(*) as col_0_0_ from instance_property instancepr0_ where (instancepr0_.value, instancepr0_.value_type)=?]; nested exception is java.sql.SQLException: Invalid column index
java.sql.SQLException: Invalid column index
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OraclePreparedStatement.setIntInternal(OraclePreparedStatement.java:4571)
at oracle.jdbc.driver.OraclePreparedStatement.setInt(OraclePreparedStatement.java:4563)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setInt(DelegatingPreparedStatement.java:116)
at org.hibernate.type.IntegerType.set(IntegerType.java:41)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:85)
at com.harris.netboss.server.modelspace.CimValueType.nullSafeSet(CimValueType.java:376)
at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:155)
at org.hibernate.loader.hql.QueryLoader.bindNamedParameters(QueryLoader.java:491)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1577)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2061)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1129)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:749)
Name and version of the database you are using:Oracle 10.2.0.1
The generated SQL (show_sql=true):Code:
select count(*) as col_0_0_ from instance_property instancepr0_ where (instancepr0_.value, instancepr0_.value_type)=?
Debug level Hibernate log excerpt:Code:
[main] DEBUG org.hibernate.SQL - select count(*) as col_0_0_ from instance_property instancepr0_ where (instancepr0_.value, instancepr0_.value_type)=?
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
[main] DEBUG org.hibernate.loader.hql.QueryLoader - bindNamedParameters() /root/cimv2 -> namespacePath [1]
[main] DEBUG org.hibernate.type.StringType - binding '/root/cimv2' to parameter: 1
[main] DEBUG org.hibernate.type.IntegerType - binding '9' to parameter: 2
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
[main] DEBUG org.hibernate.util.JDBCExceptionReporter - could not execute query [select count(*) as col_0_0_ from instance_property instancepr0_ where (instancepr0_.value, instancepr0_.value_type)=?]
java.sql.SQLException: Invalid column index
Basically the problem I'm getting is that I've got a custom type that decomposes an arbitrary object into a string representation and a type identifier for persistence into a database. It seems to work just fine for addition and removal all over the system. However, when I try to query against it, the wrong SQL appears to be generated. The nullSafeSet seems to work fine (decomposing the object), but the sql seems to only want to take one argument (the string value) and not a second one for type as the decomposition dictates. Is there a problem with my custom type or my mapping file? As well, I've never seen any SQL with the (column, column) = ?. Is that even legal for an SQL statement? Is there a better way to do persistence of arbitrary objects?