-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Problem with queries receiving proxies as parameters
PostPosted: Wed Aug 17, 2005 10:47 am 
Newbie

Joined: Fri Dec 10, 2004 8:58 am
Posts: 8
Guys,

I have a query that receives a proxy as a parameter.
The query execution throws an exception saying that the prepared statement was closed.

I digged inside hibernate code and saw that the hibernate query code initializes the proxy before setting the query parameter. When it initializes the proxy, the jdbc connection is released (release_mode is configured for AFTER_STATEMENT when created in a call to SessionFactory.getCurrentSession(), even if release_mode is configured to on_close in hibernate.cfg.xml).
Then, hibernate tries to set the parameter in the prepared statement of the query, and the exception is thrown.

My enviroment is Jboss 3.2.6, and the jtds driver is the 1.1 version.
I had this problem with the 1.0.2 version, upgraded to 1.1 and the problem continues.

Any ideas for this problem? Is this a known bug?

Thanks in advance,
Eduardo

Hibernate version: 3.0.5

Mapping documents:
<hibernate-configuration>
<session-factory name="java:/hibernate/QuickCompetence/SessionFactory">
<property name="connection.datasource">java:comp/env/jdbc/Database</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">false</property>
<property name="query.substitutions">true 1, false 0</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="connection.release_mode">on_close</property>

<mapping resource="br/com/quickmind/framework/persistence/Types.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/pde/AcaoType.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/sistema/Mensagem.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/empresa/Area.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/empresa/Cargo.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/empresa/ClassificacaoCargo.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/empresa/Empregado.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/competencia/Escala.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/competencia/Escopo.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/competencia/GrupoCompetencia.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/competencia/Nivel.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/competencia/TipoCompetencia.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/competencia/Competencia.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/avaliacao/Avaliacao.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/avaliacao/Ciclo.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/avaliacao/ItemPlanoDesenvolvimento.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/avaliacao/PlanoDesenvolvimento.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/avaliacao/ProcessoAvaliacao.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/avaliacao/resposta/Resposta.hbm.xml"/>
<mapping resource="br/com/quickmind/competence/model/avaliacao/status/Status.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
java.sql.SQLException: Invalid state, the PreparedStatement object is closed.
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.checkOpen(JtdsPreparedStatement.java:181)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.getParameter(JtdsPreparedStatement.java:247)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setParameter(JtdsPreparedStatement.java:321)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.setLong(JtdsPreparedStatement.java:490)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setLong(WrappedPreparedStatement.java:161)
at org.hibernate.type.LongType.set(LongType.java:40)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:69)
at org.hibernate.loader.hql.QueryLoader.bindNamedParameters(QueryLoader.java:264)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1178)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
... 86 more

Name and version of the database you are using:
MsSQL Server with jTDS driver

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 11:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Submit a very simple, easily runnable test case to JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 1:32 pm 
Newbie

Joined: Fri Dec 10, 2004 8:58 am
Posts: 8
I created a very simple example and simulated the problem.
But the simulation only works in a managed enviroment.

I does not happen in a simple example, since DriverManagerConnectionProvider forces the use of after_transaction instead of after_statement.

I will submit it to Jira

Thanks,
Eduardo


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 2:00 pm 
Newbie

Joined: Fri Dec 10, 2004 8:58 am
Posts: 8
I realized that the problem might be the Driver.
I analysed the code with more caution, and I think that Hibernate is probabily doing the right thing.
I created a small example that opens a database connection using its datasource, creates a prepared statement, and then closes de connection.
The prepared statement, after its corresponding connection is closed, is also closed by the driver.

That's why I get an exception when hibernate tries to use the prepared statement after loading a proxy.

I will see if there is any driver setting that handles this behaviour.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 2:49 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
eduardo.leite wrote:
I realized that the problem might be the Driver.
I analysed the code with more caution, and I think that Hibernate is probabily doing the right thing.
I created a small example that opens a database connection using its datasource, creates a prepared statement, and then closes de connection.
The prepared statement, after its corresponding connection is closed, is also closed by the driver.

That's why I get an exception when hibernate tries to use the prepared statement after loading a proxy.

I will see if there is any driver setting that handles this behaviour.

Driver doe's the right thing in this case, all correct JDBC drivers must close open statements and resultsets after connection is closed.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 3:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Sounds like you are trying to use aggressive connection release outside of JTA/JCA.

This will not work, of course ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 3:38 pm 
Newbie

Joined: Fri Dec 10, 2004 8:58 am
Posts: 8
What would be the correct settings for my hibernate.cfg.xml in this case?

My target enviroment is JBoss 3.2.6 and this is my current config file (I supressed the mapping declarations).

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="java:/hibernate/QuickCompetence/SessionFactory">
<property name="connection.datasource">java:comp/env/jdbc/Database</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">false</property>
<property name="query.substitutions">true 1, false 0</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>

</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 4:12 pm 
Newbie

Joined: Fri Dec 10, 2004 8:58 am
Posts: 8
Gavin,

I posted an issue on Jira (HHH-876) about it.

I found that there is a method on AbstractBatcher that is called to decide if the connection should be released:

public boolean hasOpenResources() {
return resultSetsToClose.size() != 0 && statementsToClose.size() != 0;
}

It will return false, if I have no resultSets opened, but one PreparedStatement opened.
As a consequence, the connection gets closed, and it closes the prepared statement that was opened before the proxy loading process.

If it is the desired behaviour, how can I turn off aggressive release in JBoss managed enviroment?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 9:59 pm 
Newbie

Joined: Fri Dec 10, 2004 8:58 am
Posts: 8
Jira Issue closed!!!!

That's one of the reasons I love open source software :)
keep up the good work guys.

Thanks for your help,
Eduardo


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.