Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6573255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:06:34+00:00 2026-05-25T15:06:34+00:00

my application conatians hibernate and spring frameworks, on tamcat server and mysql. i annotated

  • 0

my application conatians hibernate and spring frameworks, on tamcat server and mysql.

i annotated a function as transactional, and i saw that it not behaves as transacitonal method (e.g i can see the changes in the DB in query browser, before the function finish).

the method is executed from a bean, but in different thread, like this:

    executor.submit(new Runnable(){

        @Override
        public void run() {

            someSpringService.doDbStuff();
        }
    });

inside doDbStuff, i am calling to several method, and each method using the template, like this:

    return getHibernateTemplate().execute(new HibernateCallback(){
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            return session.createCriteria(MyClass.class).add(Restrictions.eq("id", id))
                    .uniqueResult();
        }
    });

sometimes, i also exeuctue within the HiberateCallback native sql query, using the session i get as an argument to doInHiberate.

my questions are –
1. is the transactional annotation ignored because i am using different thread?
2. how can i execute the function that is annotated with transactional annotation as a spring bean (and not as a regular function – maybe it will solve 1 )?
3. if i create several HibernateCallback’s within a callstack containing transactional annotation – is it behave as a transactional method? do i have to use the same session, and pass it between the inner functions?

thanks…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:06:35+00:00Added an answer on May 25, 2026 at 3:06 pm

    i can see the changes in the DB in query browser, before the function finish

    When you run your method not from within a thread does it behave differently? This might be MySQL/transaction isolation issue…

    1. is the transactional annotation ignored because i am using different thread?

    Not in this case. If you were creating a transaction in one thread and then spawning a new one, the latter would not “inherit” the transaction. In your case the transaction should start inside a new thread, behaving correctly.

    Also try running this inside doDbStuff():

    TransactionSynchronizationManager.isActualTransactionActive()
    

    to make sure.

    1. how can i execute the function that is annotated with transactional annotation as a spring bean (and not as a regular function – maybe it will solve 1 )?

    What do you mean? If you are calling someSpringService was injected by Spring and doDbStuff() is a public method annotated with @Transactional – it should just work. There are a few gotchas, however for instance – if you are inside a bean calling public transactional method from private non-transactional one might not work.

    1. if i create several HibernateCallback’s within a callstack containing transactional annotation – is it behave as a transactional method? do i have to use the same session, and pass it between the inner functions?

    HibernateCallback is clever enough to reuse the same JDBC connection -> Hibernate session -> transaction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that is based on Swing, Spring 2.5.2, Hibernate 3.3.1. If
I am using spring and hibernate together. In my application context, I have this
My web application is written using Spring MVC + Hibernate. My model is Customer
I am porting an application for KodoJDO to Hibernate. I have a query that
I am using Spring & Hibernate in my application and I want to set
I'm developing an example web-application, using JPA 2.0 entities, Hibernate 3.6.2 and Spring 3.
I have a Spring MVC based Web Application with Hibernate. Following is the directory
I am working on a Java web application that I inherited that uses Spring
I have an plain simple java application that use spring 2.5.5 and hiberate 3.3.1.GA.
I'm trying to use Spring DAO with Hibernate for a web application. When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.