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 7070627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:35:22+00:00 2026-05-28T05:35:22+00:00

I have a Spring/JPA/Groovy/Hibernate stack, (note: not grails ), and I’m finding that I’m

  • 0

I have a Spring/JPA/Groovy/Hibernate stack, (note: not grails), and I’m finding that I’m getting a No session found for current thread when trying to perform some @Transactional work on startup.

I have a controller class that, upon @PostConstruct, invokes a @Transactional method on another class which tries to populate the database with some sample data to be used in a simulation.

Here’s the controller class:

@Component
public class SimulationController {

    private TransactionTemplate transactionTemplate;
    @Autowired
    private PlatformTransactionManager transactionManager;
    @Autowired
    private IPublisher publisher;

    @PostConstruct
    public void intialize()
    {
        this.transactionTemplate = new TransactionTemplate(transactionManager);
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus arg0) {
                racePublisher.populateData();
            }
        });
    }
    //  Also tried, with no success:    
    //  @PostConstruct
    //  public void initialize()
    //  {
    //      publisher.populateData();
    //  }
}

As you can see, I’ve moved away from a pure @Transactional approach in the @PostConstruct for reasons discussed here.

My IPublisher is a groovy class, as follows:

@Component
class Publisher implements IPublisher {

@Autowired
IStockDAO stockDAO

void populateData()
{
    createStock()
}
@Transactional
void createStock()
{
    def list = [new Stock(ticker: "ADBE", name: "Adobe"),
                new Stock(ticker: "MSFT", venueCode: "Microsoft")]
    list.each { stockDAO.create it }
}

Which is an implementation of:

public interface IPublisher {

    public void populateData();
    public void createStock();
}

Note, I’ve also tried marking populateData() as @Transactional, with no effect.

In my Spring context class, I’m defining <tx:annotation-driven/>.

As far as I can tell, I’ve done everything correctly. However, I can’t seem to get this to work.

What else is required?

Updated:
Here are the beans setting up my dataAccess related beans:

<beans>
<bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <tx:annotation-driven/>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://${database.host}:${database.port}/${database.name}" />
        <property name="username" value="${database.username}" />
        <property name="password" value="${database.password}" />
        <property name="initialSize" value="5" />
        <property name="maxActive" value="50" />
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan">
            <list>
                <value>com.mangofactory.concorde</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider
                </prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop><!--  use create for full drop/create -->
                <prop key="hibernate.connection.autocommit">true</prop>
                <prop key="hibernate.statement_cache.size">0</prop>
                <prop key="hibernate.jdbc.batch_size">20</prop>
            </props>
        </property>
    </bean>
    <beans>
  • 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-28T05:35:22+00:00Added an answer on May 28, 2026 at 5:35 am

    You should use HibernateTransactionManager instead of DataSourceTransactionManager.

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

Sidebar

Related Questions

I have a JPA/Spring application that uses Hibernate as the JPA provider. In one
I have an application using Tomcat/Spring 3/JPA/Hibernate but my merges do not commit to
I'm teaching Java EE, especially JPA, Spring and Spring MVC. As I have not
When I look at Java frameworks like Hibernate, JPA, or Spring, I usually have
I have a Spring/JPA application with Hibernate as the JPA provider. I've configured a
I have a Spring/JPA/Hibernate application and am trying to get it to pass my
I am using Hibernate 3.6, JPA 2.0, and Spring 3.0.6. I have fields in
I have a Spring application which uses JPA ( Hibernate ) initially created with
I'm building a webapp using JQuery, Stripes, Spring and JPA (Hibernate). I have a
I'm using Spring + Hibernate + JPA and I have a situation where 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.