we have a spring project where we use
Spring
+ Spring Data
+ Hibernate
+ c3p0
Everything worked fine till few last versions. We started to see a lot of
INFO GooGooStatementCache:441
in our log. Moreover, after some memory issues in our server side. We started to do some analyzing of our java memory heap. seems like that in all the versions that we get a lot of INFO GooGooStatementCache:441
we have serious memory leak. com.mysql.jdbc.JDBC4Connection
does NOT get free. because of that we have many connection s that left opened.
Our suspect that the change from hibernate 3.6.3.Final
(hibernate-entitymanager
) to hibernate 3.0.Final
is causing those problems.
Anyone else experience something like that ?
Thanks,
Alon
EDIT: Switching between:
<!-- <jpa.version>2.0.0</jpa.version> -->
<hibernate.version>4.3.0-Final</hibernate.version>
<hibernate.entitymanager.version>4.3.0.Final</hibernate.entitymanager.version>
<!-- <hibernate.jpa-api.version>2.0-cr-1</hibernate.jpa-api.version> -->
To:
<jpa.version>2.0.0</jpa.version>
<hibernate.version>3.5.6-Final</hibernate.version>
And this:
<dependency>
<groupId>org.hibernate.java-persistence</groupId>
<artifactId>jpa-api</artifactId>
<version>${hibernate.jpa-api.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.entitymanager.version}</version>
<scope>compile</scope>
</dependency>
To:
<!-- Hibernate and JPA -->
<!-- seems like we get jppa api from hibernate-entitymanager -->
<!-- <dependency> -->
<!-- <groupId>org.hibernate.java-persistence</groupId> -->
<!-- <artifactId>jpa-api</artifactId> -->
<!-- <version>${hibernate.jpa-api.version}</version> -->
<!-- <scope>compile</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.entitymanager.version}</version>
<scope>compile</scope>
</dependency>
prevents the INFO GooGooStatementCache:441 - Multiply prepared statement!
issue
so seems there is some kind of problem with our settings and hibernate 4.3.0-final
any ideas?
EDIT 2:
changing to 4.3.1.Final does NOT solves this issue
EDIT 3
thanks for the response
my guess is that its something that doesnt work right with the c3p0
and the new hibernate
here is how we set them
<!-- Declare a datasource that has pooling capabilities-->
<bean id="jpaDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close"
p:driverClass="${app.jdbc.driverClassName}"
p:jdbcUrl="${app.jdbc.url}"
p:user="${app.jdbc.username}"
p:password="${app.jdbc.password}"
p:acquireIncrement="5"
p:idleConnectionTestPeriod="60"
p:maxPoolSize="100"
p:maxStatements="50"
p:minPoolSize="10" />
<!-- Declare a JPA entityManagerFactory -->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:persistenceXmlLocation="classpath*:META-INF/persistence.xml"
p:persistenceUnitName="hibernatePersistenceUnit"
p:dataSource-ref="jpaDataSource"
p:jpaVendorAdapter-ref="hibernateVendor"/>
<!-- Specify our ORM vendor -->
<bean id="hibernateVendor" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
p:showSql="false"/>
<!-- Declare a transaction manager-->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"/>
and here is persistence file
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="1.0">
<persistence-unit name="hibernatePersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value=${show.sql} />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
</properties>
<mapping-file>META-INF/orm.xml</mapping-file>
</persistence-unit>
</persistence>
EDIT 4 seems that move to hibernate 4.3.1.FINAL DOES fixes the issue. dont get any warning about prepare statement to log. and memory analyzer doesnt show any leak on db connection.
question
what is the best way to connect hibernate
and c3p0
and spring
? using hibernate-c3p0
package or adding c3p0
package to pom?
So, I can't explain why you are seeing more of this in newer versions of Hibernate, but what the message you are seeing means is that your application is trying to prepare a PreparedStatement that has already been prepared and cached by the very same database Connection. However, the cached Statement cannot be used, because it is still in use, it has not yet been close()ed. So a new copy of the same Statement is being prepared. (The cache will hold both copies, in case you simultaneously reuse the Statement often.)
In theory, there are scenarios in which this might be exactly what you intend to do. For example, while traversing recursive structures flattened into a database table, you might reuse the same query with different parameters to drill down levels while a top level query remains open.
Still, in practice this is rare. Usually if you are getting this message, it probably means that your application is not promptly close()ing Statements. From what you describe, it sounds like you might have a Connection leak too, though you haven't reported the usual result of that, the app hangs when the pool reaches maxPoolSize
. (You haven't reported much about your c3p0 config; maybe you have set maxPoolSize
very large and you run into memory problems before pool exhaustion.)
Some things you might try:
1) Check if you have a Connection leak. See here
2) Simplify the issue: See if the problem is limited to Statement caching by turning Statement caching off and comparing behavior. Set c3p0 params maxStatements
and maxStatementsPerConnection
both to zero.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With