Spring Hibernate “Closed Statement / ResultSet”

I was encountering this exception, complaining about “cannot operate on closed statement or resultset”.

I have a domainClass map to one table. The domain class use an ID class for composite identity. The domain class also use another class to resolve one property.

	<class name="AbstractHibernatePredicate" table="jql_mapping" lazy="false" mutable="true" discriminator-value="not null">
		<cache usage="read-only"/>
    	<composite-id name="jqlMappingID" class="com.bfm.predicate.JqlMappingID" >
			<key-property name="purpose" column="purpose" type="&TrimmedString;" />
			<key-property name="evalOrder" column="eval_order" />
		<property name="xxxx" column="xxxx" type="&TrimmedString;" />
		<subclass name="ConcreteHibernatePredicate" discriminator-value="not null">
            <property name="expression"  column="jql" type="SomeExpressionType"/>

SomeExpressionType is org.hibernate.usertype.CompositeUserType. It overrides nullsafeget

    public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException {
        String expr = null;
        try {
        	String prog = resolveProgram(rs);
            if (rs.isFirst() || macroFactory.get() == null || !macroFactory.get().containsKey(prog)) {
                List<xx> xx= session.getNamedQuery("byProgram").list();
            return getParsedExpression(rs.getString(names[0]),prog);
        } catch (Exception e) {
            log.warn("Exception while parsing BQLExpression. Failed expression: " + expr + ". Error " + e.getMessage());
            return new BQLExpression("1=2");

within above method, it use same session to invoke another query and execute. This results the existing resutlSet detached, because this configuration:

<prop key="hibernate.connection.release_mode">after_transaction</prop>


<prop key="hibernate.connection.release_mode">after_statement</prop>

the only way to work is

<!--prop key="hibernate.connection.release_mode">after_statement</prop-->


<prop key="hibernate.connection.release_mode">on_close</prop>


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s