Org.hibernate.TransactionException:JDBC commit failedDescription The server encountered an internal error that prevented it from fulfilling this request.exceptionOrg.springframework.web.util.NestedServletException:Request processing failed; Nested exception is Org.springframework.orm.hibernate3.HibernateSystemException:JDBC commit failed; Nested exception is Org.hibernate.TransactionException:JDBC commit failedOrg.springframework.orm.hibernate3.HibernateSystemException:JDBC commit failed; Neste
I read the hibernate in the book I'll post the source code and configuration files. Let's see what it is,I. hibernate. cfg. xml file "-// Hibernate/hibernate configuration DTD 3.0 // en"Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd>
Note: it should be ", but who will destroy it? A thread needs to follow hibernate. c3p0. idle_test_periodSet the time interval to automatically verify these linked objects and destroy timeout -->Ii. Stud
Spring with C3P0 connection pool applicationContext. xml file:
Article Source: http://www.javaeedev.com/blog/article.jspx? ArticleId = ff8080811a2a52f2011a383e5baf09da
public class c3p0demo{/*Code configuration*/public void Fun1 () {To create a connection pool objectCombopooleddatasource DataSource = new Combopooleddatasource ();Four-parameter configuration for connection poolingDatasource.setdriverclass ("Com.mysql.jdbc.Driver");Datasource.setjdbcurl ("Jdbc:mysql://loaclhost:3306/mydb");Datasource.setuser ("root");Datasource.setpassword ("root");Pool ConfigurationDatasource.setacquireincrement (5);Datasource.setinitialpoolsize (20);Datasource.setminpoolsize (
The following parameters are the basic configuration parameters used:Initialpoolsize:Number of connections a pool will try to acquire upon startup. shocould be between minpoolsize and maxpoolsizeNumber of links obtained during connection pool initialization, between minpoolsize and maxpoolsize
Minpoolsize:Minimum number of connections a pool will maintain at any given time.Minimum number of links
Maxpoolsize:Maximum number of connections a pool will maintain at any given time.Max connections
Hibernate 1-to-many deadlockFrequent deadlocks in spring + hibernate + Struts + SQL databases. The query is deadlocked after update is executed.
It's dead. You have to stop tomcat to continue running.
Solution: use the database connection pool c3p0-->
We usually use data connection pools in actual projects, because the overhead is relatively small;
Jar package with c3p0 in the hibernate package;
Add the following to hibernate. cfg. xml:
1. Jar Package HIBERNATE-RELEASE-4.1.8.FINAL\LIB\OPTIONAL\C3P02. Join the configuration:database connection pool minimum connections--The connection pool itself does not remove itself from the connection pool, but rather has a thread that groups it at certain intervals.This thread compares the time difference between the last time the connection object was used and the current one to timeout, and then decides to destroy the connection object.The number of cache statement-Using the
Transfer example (1): Dao implementation (in this example, QueryRunner is used to execute SQL statements, and the data source is C3P0 ),
Disadvantage: the Dao layer completes Service-level operations, which is not conducive to later code modification and reconstruction.
1. Create C3P0Util on your own
Account Database
2. jar package
3. Dao Layer
Interface:
Package com. learning. dao; import com. learning. domain. account; public interface AccountDao
We typically use data connection pooling in actual projects because the overhead is relatively small;
A jar package with C3P0 in the Hibernate package;
Add in Hibernate.cfg.xml:
I. Proxool configuration
1. Persistence.xml
1.
2. Add the Proxool.xml file in the SRC directory, the file configuration is as follows
1.
Second, c3p0 link pool configuration
1.
Cons: The DAO level completes the service level operation, which is detrimental to later code modification and refactoring1. Create your own C3p0utilAccount Database2.jar Pack3.Dao levelInterface: PackageCom.learning.dao;ImportCom.learning.domain.Account; Public InterfaceAccountdao {/*** Transfer *@paramfromname Transfer out user *@paramtoname Transfer to User *@paramMoney transfer Amount*/ Public voidUpdateaccount (String fromname,string ToName,DoubleMoneythrowsException;}Implementation cla
C3P0 Database Connection Pool usage1. Copy jar package: C3p0-0.9.1.2.jar C3p0-0.9.1.2-jdk1.3.jar C3p0-oracle-thin-extras-0.9.1.2.jar (required by Oracle)2, write the preparation file in the SRC directory: c3p0-config.xml (the name can only be this)3, Class C3p0utilC3p0-confi
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.