• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Transactions in Spring + Hibernate

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys!

I�m trying using Spring + Hibernate to persist system�s objects (Hibernate) and control transactions (Spring).
But every interaction with DB (MySQL) a new connection is opened, ignoring my pool (c3p0) configuration.

My example is so simple, User and Note objects to persist.
My example is organized in three packages:

Model
There are two classes:
User
Note

These objects are annotated to Hibernate.

DAO
There are three interfaces:
GenericDAOInterface
UserDAOInterface
NoteDAOInterface

And three implementations:
SpringDAO extends HibernateDaoSupport
and implements GenericDAOInterface
UserDAO extends SpringDAO
and implements UserDAOInterface
NoteDAO extends SpringDAO
and implements NoteDAOInterface

These objects are annotated with @Repository.

Facade
There are two interfaces:
UserFacadeInterface
NoteFacadeInterface

And two implementations:
UserFacade implements UserFacadeInterface
NoteFacade implements NoteFacadeInterface

These objects are annotated with @Transactional.

When I use the system this work fine, I can persiste my beans. I look in MySQL and my system start the first operation (login) creating three connections and to every operation with DB (list my notes, view register/view page with correct register data filed, etc) is opened a connection in MySQL.

I tried create a TransactionManager, TransactionInterceptor, etc� into my applicationContext.xml but I cant�t make Spring use my transaction configuration!!! I tried put in dataSource bean a declararion type: <property name="transactionManager"><ref local="transactionManager"/></property> but don�t work or in Hibernate properties: <prop key="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>.

Someone can help me? My config file is:

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you trying to use transactions driven by annotations?

If yes please try to change the bean <tx:annotation-driven/> to this

<tx:annotation-driven transaction-manager="transactionManager"/>
 
Jean Jorge Michel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is not it, do not work ;(

I am looking in MySQL console (Windows� command prompt) and for all hit is open a new connection
This problem will kill my project, if I do not able to control this problem Spring + Hibernate will be removed from the project and I will be forced to use procedures + JDC (noooooo!!!).

Someone have any idea to help me?

Thanks.

My new attempt is:

 
Satish Kandagadla
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jean Jorge Michel:
Hi,
Is not it, do not work ;(

I am looking in MySQL console (Windows� command prompt) and for all hit is open a new connection
This problem will kill my project, if I do not able to control this problem Spring + Hibernate will be removed from the project and I will be forced to use procedures + JDC (noooooo!!!).

Someone have any idea to help me?

Thanks.

My new attempt is:



Your transaction beans are so confusing. Are you using all the beans in the configuration that you pasted above? I would first clean up the unused beans and give it a try.
 
Jean Jorge Michel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Satish, thanks for your attention.

I am new Spring�s user (of course hahaha), and this configuration is the result of hours and hours fighting with Spring and search on Google a silver bullet to save me.

Today on morning (now in Rio de Janeiro/Brazil is 10: 50AM) I tried:



And the problem is the same.

Let me show �all problem�.

I Start MySQL DB and log in, is created 2 connections.
When I start my Tomcat and do login my pool is initialized and is created three new connections.
After login my JSF navigation rule redirect the browser to home, this page search on DB my notes and show it in a table. In this point is created more three connections. Now I have 8 connections with MySQL.

My transaction management is ignored or my pool is crazy =)

Here is my codes.

First login flow.



Second home flow:



Some idea?

Thanks for all help.
 
Satish Kandagadla
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jean Jorge Michel:
Satish, thanks for your attention.

I am new Spring�s user (of course hahaha), and this configuration is the result of hours and hours fighting with Spring and search on Google a silver bullet to save me.

Today on morning (now in Rio de Janeiro/Brazil is 10: 50AM) I tried:



And the problem is the same.

Let me show �all problem�.

I Start MySQL DB and log in, is created 2 connections.
When I start my Tomcat and do login my pool is initialized and is created three new connections.
After login my JSF navigation rule redirect the browser to home, this page search on DB my notes and show it in a table. In this point is created more three connections. Now I have 8 connections with MySQL.

My transaction management is ignored or my pool is crazy =)

Here is my codes.

First login flow.



Second home flow:



Some idea?

Thanks for all help.



I do not see anything wrong with the transaction beans. How are you saying that the transaction attributes are not working? What are you expecting from the annotations given in your application?
 
Jean Jorge Michel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, I resolved this error.

In a Brazilian JUG e-mail list (RSJUG) one participant named Julio told me that I should start Spring`s context together my application and not instantiate in every backbean`s method an ApplicationContext object. It was my error, creating always a new instance of my pool, etc�

Searching in Google I found how make it and now all it is working fine

My web.xml:



In faces-config.xml I defined that the backbean receive a facade.



Set how resolves this EL expression

In faces-config.xml too:



In login backbean have an attribute named userFacade, getters and setters to this and none instantiate code of ApplicationContext object, Spring inject it to me.

Thanks for all answers.
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic