[Hibernate-JIRA] Created: (HHH-3359) Loader leaks memory when ResultSet wrapping is enabled
by Frans Flippo (JIRA)
Loader leaks memory when ResultSet wrapping is enabled
------------------------------------------------------
Key: HHH-3359
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3359
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.3.0.CR1, 3.2.6
Environment: Hibernate 3.2.6 GA, Oracle 10g database, Oracle JDBC drivers 10.2.0.1.0 for JDK14
Reporter: Frans Flippo
Priority: Minor
Attachments: ResultSetWrapper.java
This issue was already reported on the forums (http://forum.hibernate.org/viewtopic.php?t=968578), but I can find no actual JIRA entry. The issue is that when the hibernate.jdbc.wrap_result_sets property is set to true, ResultSets are never removed from the AbstractBatcher's resultSetsToClose set, eventually causing memory to fill up with ResultSet objects and their associated resources (like PreparedStatements).
This issue was witnessed in 3.2.6, but a look at the 3.3 CR1 source code reveals that it's still in there.
What happens:
1) org.hibernate.loader.Loader.doQuery calls org.hibernate.loader.Loader.getResultSet
2) org.hibernate.loader.Loader.getResultSet calls Batcher.getResultSet. The AbstractBatcher implementation creates a ResultSet by executing the query and adds it to the AbstractBatcher's resultSetsToClose Set
3) Loader then calls its wrapResultSetIfEnabled method to wraps the ResultSet in a ResultSetWrapper if the wrap_result_sets option is enabled.
4) In Loader.doQuery's finally block, Batcher.closeQueryStatement is called with the PreparedStatement and the *wrapped* ResultSet as parameters
5) closeQueryStatement does:
if ( resultSetsToClose.remove( rs ) ) {
logCloseResults();
rs.close();
}
6) resultSetsToClose.remove(rs) will always return false if the ResultSet was wrapped, as ResultSetWrapper does not override equals()/hashCode() (and therefore inherits Object's equals() and hashCode()). This means the reference to the original (unwrapped) ResultSet remains (is not removed from the Set) and the ResultSet is not closed either as a result.
Workaround: Set hibernate.jdbc.wrap_result_sets to false
Solution: implement ResultSetWrapper.equals()/hashCode() (see attached ResultSetWrapper.java)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 8 months
[Hibernate-JIRA] Created: (HHH-3203) DerbyDialect Bug
by Bernd Farka (JIRA)
DerbyDialect Bug
----------------
Key: HHH-3203
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3203
Project: Hibernate3
Issue Type: Bug
Environment: Hibernate 3.2.6 GA, Vista, Current ApacheDerby, BEA Jrockit
Reporter: Bernd Farka
When i execute following Query
select sum(t.ammount) from Transaction t where t.bookingDate >= :from and t.bookingDate <= :until and t.account = :account"
Hibernate throws this Exception (on Mysql it works!)
2008-03-25 20:07:21,460 [Main Thread] DEBUG org.hibernate.util.JDBCExceptionReporter - could not execute query [select transactio0_.category_id as col_0_0_, sum(transactio0_.ammount) as col_1_0_, category1_.categoryId as categoryId2_, category1_.categroyName as categroy2_2_ from tbl_transactions transactio0_ inner join tbl_category category1_ on transactio0_.category_id=category1_.categoryId where transactio0_.bookingDate>=? and transactio0_.bookingDate<=? and transactio0_.account_id=? group by transactio0_.category_id]
java.sql.SQLException: The SELECT list of a grouped query contains at least one invalid expression. If a SELECT list has a GROUP BY, the list may only contain valid grouping expressions and valid aggregate expressions.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver30.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
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.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.farkarich.bankmanager.MainFrame.updateData(MainFrame.java:317)
at org.farkarich.bankmanager.MainFrame.<init>(MainFrame.java:342)
at org.farkarich.bankmanager.StartClass.main(StartClass.java:27)
Caused by: ERROR 42Y30: The SELECT list of a grouped query contains at least one invalid expression. If a SELECT list has a GROUP BY, the list may only contain valid grouping expressions and valid aggregate expressions.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.VerifyAggregateExpressionsVisitor.visit(Unknown Source)
at org.apache.derby.impl.sql.compile.QueryTreeNode.accept(Unknown Source)
at org.apache.derby.impl.sql.compile.ResultColumn.accept(Unknown Source)
at org.apache.derby.impl.sql.compile.QueryTreeNodeVector.accept(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 23 more
2008-03-25 20:07:21,462 [Main Thread] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 20000, SQLState: 42Y30
2008-03-25 20:07:21,462 [Main Thread] ERROR org.hibernate.util.JDBCExceptionReporter - The SELECT list of a grouped query contains at least one invalid expression. If a SELECT list has a GROUP BY, the list may only contain valid grouping expressions and valid aggregate expressions.
2008-03-25 20:07:21,465 [Main Thread] DEBUG org.hibernate.jdbc.JDBCContext - after autocommit
2008-03-25 20:07:21,465 [Main Thread] DEBUG org.hibernate.jdbc.ConnectionManager - aggressively releasing JDBC connection
2008-03-25 20:07:21,465 [Main Thread] DEBUG org.hibernate.jdbc.ConnectionManager - releasing JDBC connection [ (open PreparedStatements: 1, globally: 1) (open ResultSets: 0, globally: 0)]
2008-03-25 20:07:21,465 [Main Thread] DEBUG org.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
Exception in thread "Main Thread" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2216)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.farkarich.bankmanager.MainFrame.updateData(MainFrame.java:317)
at org.farkarich.bankmanager.MainFrame.<init>(MainFrame.java:342)
at org.farkarich.bankmanager.StartClass.main(StartClass.java:27)
Caused by: java.sql.SQLException: The SELECT list of a grouped query contains at least one invalid expression. If a SELECT list has a GROUP BY, the list may only contain valid grouping expressions and valid aggregate expressions.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.<init>(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.<init>(Unknown Source)
at org.apache.derby.jdbc.Driver30.newEmbedPreparedStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
... 10 more
Caused by: ERROR 42Y30: The SELECT list of a grouped query contains at least one invalid expression. If a SELECT list has a GROUP BY, the list may only contain valid grouping expressions and valid aggregate expressions.
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.VerifyAggregateExpressionsVisitor.visit(Unknown Source)
at org.apache.derby.impl.sql.compile.QueryTreeNode.accept(Unknown Source)
at org.apache.derby.impl.sql.compile.ResultColumn.accept(Unknown Source)
at org.apache.derby.impl.sql.compile.QueryTreeNodeVector.accept(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 23 more
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 8 months
[Hibernate-JIRA] Created: (HHH-2960) Add Interceptor to the openSession method the CurrentSessionContexts use
by Shawn Clowater (JIRA)
Add Interceptor to the openSession method the CurrentSessionContexts use
------------------------------------------------------------------------
Key: HHH-2960
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2960
Project: Hibernate3
Issue Type: Improvement
Components: core
Affects Versions: 3.2.5
Reporter: Shawn Clowater
Priority: Minor
Ran into a minor snag earlier where I was rigging up the stateful audit interceptor and didn't have a clean hook to jack the interceptor for my current session.
The sample code illustrates the use of the interceptor by using the sessionFactory.openSession(Interceptor) method and then goes on to say with the wave of a hand that if you're using the getCurrentSession functionality that you'll have to override whatever CurrentSessionContext you're using. That's a little bit more cumbersome that I was hoping for but to make matters worse the method that the ThreadLocalCurrentSessionContext is using to obtain the session is:
public org.hibernate.classic.Session openSession(
final Connection connection,
final boolean flushBeforeCompletionEnabled,
final boolean autoCloseSessionEnabled,
final ConnectionReleaseMode connectionReleaseMode) throws HibernateException;
There are no other constructors that I can see that combine all of these parameters with the addition of an Interceptor parameter. It would be a nice to have if there were an overloaded method that accepted the addition of an Interceptor.
I worked around it for now but I am ashamed at the way I'm storing state for my interceptor.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 8 months
[Hibernate-JIRA] Created: (HHH-2640) Clob management and deadlock
by Samuel Emangard (JIRA)
Clob management and deadlock
----------------------------
Key: HHH-2640
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2640
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.0.ga
Environment: JDK 1.5, Oracle 10g v2
Reporter: Samuel Emangard
Priority: Trivial
Attachments: Samuel.rar
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
'-//Hibernate/Hibernate Mapping DTD 3.0//EN'
'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
<hibernate-mapping package="com.toluna.samuel.hibernate.emailtemplate">
<class name="EmailTemplate" table="EmailTemplate">
<id name="id" type="long">
<column name="template_id" not-null="true"/>
<generator class="native"/>
</id>
<property name="name">
<column name="email_name" not-null="false"/>
</property>
<property name="htmlTextClob" type="clob">
<column name="html_Text" not-null="false"/>
</property>
<property name="plainTextClob" type="clob">
<column name="plain_Text" not-null="false"/>
</property>
</class>
</hibernate-mapping>
Extract also of my Java bean:
ublic class EmailTemplate {
private long id;
private String name;
private String plainText = " ";
private String htmlText = " ";
private Clob plainTextClob;
private Clob htmlTextClob;
...
Code of the test case:
Session ss = HibernateUtil.getSessionFactory().getCurrentSession();
//S_LOGGER.debug("Number of current Hibernate sessions: "+ HibernateUtil.getSessionFactory().getStatistics().getSessionOpenCount());
ss.getTransaction().begin();
EmailTemplate et = (EmailTemplate) ss.load(EmailTemplate.class, new Long("299941536982302"));
S_LOGGER.debug(et.getName());
Thread.sleep(5000);
S_LOGGER.debug("BEFORE FLUSH");
ss.flush();
S_LOGGER.debug("AFTER FLUSH");
ss.getTransaction().commit();
The generated SQL :
The load statement is always generated:
/* load com.toluna.samuel.hibernate.emailtemplate.EmailTemplate */ select
emailtempl0_.template_id as template1_0_0_,
emailtempl0_.email_name as email2_0_0_,
emailtempl0_.html_Text as html3_0_0_,
emailtempl0_.plain_Text as plain4_0_0_
from
EmailTemplate emailtempl0_
where
emailtempl0_.template_id=?
....
Depending on the implementation of the getter, the following update statement is generated:
/* update
com.toluna.samuel.hibernate.emailtemplate.EmailTemplate */ update
EmailTemplate
set
email_name=?,
html_Text=?,
plain_Text=?
where
template_id=?
Here is the getter:
Clob getHtmlTextClob() {
//1-
//return Hibernate.createClob(htmlText != null ? htmlText : " ");
//2-
return htmlTextClob;
}
With 1- the update statement is generated
With 2- the update statement is not generated
Why?
Extract of the setter:
void setHtmlTextClob(Clob htmlTextClob) {
this.htmlTextClob = htmlTextClob;
try {
if (htmlTextClob != null) {
htmlText = HibernateUtil.getStringFromClob(htmlTextClob);
//htmlText = "samuel";
} else
htmlText = "";
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
I have also another more critical issue which seems tied to the previous:
If I write the following piece of test code instead of the one shown above:
Session ss = HibernateUtil.getSessionFactory().openSession();
//S_LOGGER.debug("Number of current Hibernate sessions: "+ HibernateUtil.getSessionFactory().getStatistics().getSessionOpenCount());
EmailTemplate et = (EmailTemplate) ss.load(EmailTemplate.class, new Long("299941536982302"));
S_LOGGER.debug(et.getName());
Thread.sleep(5000);
S_LOGGER.debug("BEFORE FLUSH");
ss.flush();
S_LOGGER.debug("AFTER FLUSH");
As you can see in this piece of code i do not manage transactions explicitly and in that case my 2 java threads generated update statements which never ended: there was a deadlock on the DB.
During the last test, If I still did not manage transactions explicitly but I modified the getter like that:
Clob getHtmlTextClob() {
return htmlTextClob;
}
Then neither update statements nor deadlock were generated.
I wrote this piece of test code to reproduce deadlock I was facing on my Jonas server.
Could you please help me to understand this behaviour?
Here is anextract of my hibernate.cfg.xml:
<property name="connection.url">jdbc:oracle:thin:@192.168.2.7:1521:tlorcl1</property>
<property name="connection.username">samuel</property>
<property name="connection.password">toluna</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="myeclipse.connection.profile">QA</property>
<property name="current_session_context_class">thread</property>
Thanks in advance
Regards
Samuel
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 9 months
[Hibernate-JIRA] Created: (HHH-3646) implement Criteria API querying of collection-of-component
by David Mansfield (JIRA)
implement Criteria API querying of collection-of-component
----------------------------------------------------------
Key: HHH-3646
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3646
Project: Hibernate Core
Issue Type: Patch
Components: query-criteria
Affects Versions: 3.2.6
Environment: hibernate 3.2.6, tested on linux 64-bit openjdk 1.6 (jdk1.5 for compiling). mapping created under annotations 3.3.1ga
Reporter: David Mansfield
Attachments: hib-core-query-collection-of-elements-3_2_6.patch
the attached patch implements a first cut, extremely rough, yet working extension of the CriteriaQueryTranslator class to allow for querying of properties of components inside a collection, or querying properties of associated elements of components inside a collection. eg for
* code is lightly tested, this example is for illustrative purposes only
* i use annotations, so my example is expressed in those terms, and i've only tested with mappings generated via annotations, however, the modifications only apply to the core.
@Entity
class Order {
@Id
String id;
@CollectionOfElements
Set<OrderLineItem> lineItems;
}
@Embeddable
class OrderLineItem {
@ManyToOne
Product product;
Integer quantity;
}
@Entity
class Product {
String name;
}
Then we can now do:
Criteria c = session.createCriteria(Order.class)
.createCriteria("lineItems")
.add(Restrictions.gt("quantity", new Integer(1))
.list();
or
Criteria c = session.createCriteria(Order.class)
.createCriteria("lineItems")
.createCriteria("product")
.add(Restrictions.like("name", "cake%")
.list();
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 9 months