wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Problem with Hibernate-C3P0-connectionPool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with Hibernate-C3P0-connectionPool" Watch "Problem with Hibernate-C3P0-connectionPool" New topic
Author

Problem with Hibernate-C3P0-connectionPool

Jesus Schneider
Greenhorn

Joined: Oct 17, 2012
Posts: 28
Hello!
I'm creating a web application with Netbeans 7.3, JSF 2.1 with Primefaces 3.5 and Hibernate 3.2.5. I'm running it on a glassfish server 3.1.2
My project has some upkeeps ( I'm not sure about how to call it in english, I'm talking about a screen where you can create, update and delete data ) as this one:

(I changed some original names and texts from spanish to english)
MANOPINIONES VIEW:



MANOPINIONES BACKING BEAN:



As you can see its a very simple example of "upkeep" and with the original configuration it worked perfectly.


I wanted to implement a conection pool using the c3p0 library to improve the speed so I added this lines on the hibernate.cfg.xhtml

HIBERNATE.CFG.XHTML



I also created a connection pool on the glassfish server.
I downloaded and added the "mysql-connector-java-5.0.8-bin" to my server. To configure the pool I just changed these optional properties:

Databasename = the_database_name
Password = the_password
Portnumber = 3306
Servername = localhost
User = root

And finally I created a JDBC Resource called "jdbc/PoolAgencia"

It seemed to work well, data was retrieved very fast at other points of the web. Then I used the "upkeep" this way:
-I went to the "upkeep" page.
-I introduced a code (it doesn't mind whether it's a new one or an existing one)
-I pressed the "search" button.(if the code exists in the database it is retrieved, other way a new one is created)
-Then I press the "cancel" button (should undo all changes or cancel a newly created registry) and I get this error:



If I use the "upkeep" that way:
-I go to the "upkeep" page.
-I introduce a code (it doesn't mind whether it's a new one or an existing one)
-I press the "search" button.(if the code exists in the database it is retrieved, other way a new one is created)
-Then I press the "OK" button (should save all changes) and I get this error:




As I read both errors I understand that transactions aren't working properly with the pool. I think it's a problem of the connection pool or a hibernate configuration issue. I have made a search over the net and I have tried to change some configuration options of the connection pool without luck.
Why is this happening? Can someone help me?
Thanks in advance!!
Carles Gasques
Ranch Hand

Joined: Apr 19, 2013
Posts: 199
    
    1
Hi Jesus,

I think that you could translate 'mantenimiento' as CRUD.

The key of the issue is already in the trace you have attached

You must disable autocommit if you plan to use transactions (because you want to be in control when a commit or rollback has to be performed).

Cheers,
Jesus Schneider
Greenhorn

Joined: Oct 17, 2012
Posts: 28
Thank you for answering so fast Carles.
I didn't explain it on my first post. I have tried to disable the autocommit with no luck. Where should I do it??
Thank you!
Carles Gasques
Ranch Hand

Joined: Apr 19, 2013
Posts: 199
    
    1
Hi Jesus,

Well I understand that you have already tried to inform the hibernate property in the persistence.xml file with no luck.
Is it the case?


Jesus Schneider
Greenhorn

Joined: Oct 17, 2012
Posts: 28
That's right Carles. I used the same property you wrote in the hibernate.cfg.xml with no effect at all. The same error continues appearing. That's the reason why I'm so disoriented...
Any idea?
Thank you!
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

I am sorry if answer is not acceptable. But I also had this error :

It was caused by mixing spring delarative transaction with programmatic transaction.
The problem was that spring managed(ruled) transaction for that method via annotations. When I tried to commit transaction programmatically it gave this error.
The problem was resolved by turning off spring declarative transaction for that method by annotation:
@Transactional(propagation = Propagation.NOT_SUPPORTED)


True person is moral, false is right!
Carles Gasques
Ranch Hand

Joined: Apr 19, 2013
Posts: 199
    
    1
Hi Jesus,

Then there is another place where autocommit is set to true.
Options:

- MySQL driver (if not support transactions setrelaxAutoCommit=true)
If the version of MySQL the driver connects to does not support transactions,
still allow calls to commit(), rollback() and setAutoCommit() (true/false, defaults to 'false')?



- C3PO pool (seems is already false by default)
autoCommitOnClose Must be set in c3p0.properties, C3P0 default: false


- Tomcat resources
defaultAutoCommit - true or false: default auto-commit state of the connections created by this pool. Default: true



Set autocommit false on hibernate configuration xml and test if some of this hints is the correct one.
I hope so...
Jesus Schneider
Greenhorn

Joined: Oct 17, 2012
Posts: 28
Hi!
Volodymyr, I'm afraid that your answer is not related with my problem, but thank you anyway.
Carles: you almost got it!
As I said I have my connection pool on glassfish. There are 161 optional parameters. I had missed one of them called "relaxAutoCommit". I just put it on TRUE and everything works perfectly!!
Thank you very much!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Hibernate-C3P0-connectionPool
 
Similar Threads
IllegalStateException at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.j
StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet
Error while deploying a war file in GlassFish
ajax and p:picklist (PrimeFaces)
Unable to retrieve EntityManagerFactory, everything configured correctly but does not run!!!