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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:41:52+00:00 2026-05-26T07:41:52+00:00

I am trying to write a simple spring-hibernate command line application with transaction management

  • 0

I am trying to write a simple spring-hibernate command line application with transaction management support, but I am constantly getting
“org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here”

my spring config file (applicationContext.xml)

    <!-- Context Provider -->
<bean class="com.rps.util.ContextUtil" />
<!-- The transactional service objects -->
<bean id="service" class="com.rps.service.DefaultService" p:parentDao-ref="parentDao" p:childDao-ref="childDao" />

<!--the transactional advice-->
<tx:advice id="txAdvice" transaction-manager="txManager">
    <tx:attributes>
        <tx:method name="get*" read-only="true" />
        <tx:method name="*" />
    </tx:attributes>
</tx:advice>

<!--this transactional advice runs for any service method execution-->
<aop:config>
    <aop:advisor pointcut="execution(* com.rps.service..*.*(..))" advice-ref="txAdvice" />
</aop:config>

<!-- The PlatformTransactionManager -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory" />

<!-- The DataSource -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="com.mysql.jdbc.Driver" p:url="jdbc:mysql://localhost:3306/OsivTest" p:username="XXX" p:password="YYY" />

<!-- Session Factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" p:dataSource-ref="dataSource">
    <property name="mappingResources">
        <list>
            <value>com/rps/domain/Parent.hbm.xml</value>
            <value>com/rps/domain/Child.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

<!-- Data Access Objects -->
<bean id="parentDao" class="com.rps.data.hbm.HibernateParentDao" p:sessionFactory-ref="sessionFactory" />
<bean id="childDao" class="com.rps.data.hbm.HibernateChildDao" p:sessionFactory-ref="sessionFactory" />

DAO Code (Session Factory object set by IoC container as configured in context file above)

public List<T> findAll() {
    return sessionFactory.getCurrentSession().createCriteria(getPersistentClass()).list();
}

DefaultService Class: (parentDao injected from IoC container)

public class DefaultService implements Service {

@Override
public List<Parent> getAllParent() {
    return parentDao.findAll();
}
    //Other methods
}

Main method code:

public static void main(String[] args) {

    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    Service s = (Service) context.getBean("service");
    s.getAllParent();
}

I am using hibernate version 3.1.3 and spring 3.
How do we configure one session per thread? I believe the issues is that no session is being associated with my execution thread. I was assuming that transaction manager will open a session if not already found, but it does not do so.

  • 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-26T07:41:52+00:00Added an answer on May 26, 2026 at 7:41 am

    Quote 1:

    I am using hibernate version 3.1.3 and spring 3

    Quote 2:

    Note
    As of Spring 3.0, Spring requires Hibernate 3.2 or later.

    (Source)

    BTW, the current stable Hibernate version is 3.6.7

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

Sidebar

Related Questions

I'm trying to write a simple Spring AOP app, but I have problem with
I've got weird problem. I'm trying to write simple game in C++, but I
I am trying to write some simple predicate using boost::lambda and I am getting
I am trying to write a simple utility webcontrol to display one-line messages inside
I am trying to write a simple android application to help interpret some lab
I am trying to write a simple desktop application for managing accounts. I am
I'm trying to write a simple WCF Server + gSOAP client proof-of-concept application using
I'm trying to write a simple client/server chat application in 2 languages - Java
I am trying to write a simple application that loads images that are stored
I am trying to write a simple mail client in Java with sockets. But

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.