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

  • Home
  • SEARCH
  • 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 7766241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:21:52+00:00 2026-06-01T15:21:52+00:00

Here i am facing a problem that , i configured the hibernate sessionfactory in

  • 0

Here i am facing a problem that , i configured the hibernate sessionfactory in application.xml file and after how can i get the sessionFactory in my HibDao class (user defined class) for enabling user friendliness like begin(),commit(),rollback() with extending HibernateDaoSupport class..

Here is my application-hibernate.xml file :

  <beans>   

<bean id="sessionFactory"       class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">     
    <property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
</bean>



<!-- Transaction manager for a single Hibernate SessionFactory (alternative 
    to JTA) -->
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
        <ref local="sessionFactory" />
    </property>
</bean>


<!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->

<!-- Data access object: Hibernate implementation. -->

<bean id="HibernateSpringDaoTarget" class="com.netprofit.dao.HibernateSpringDAOImpl">
    <property name="sessionFactory">
        <ref local="sessionFactory" />
    </property>
</bean>

<!-- - Transactional proxy for Application's central data access object. 
    - - Defines specific transaction attributes with "readOnly" markers, - which 
    is an optimization that is particularly valuable with Hibernate - (to suppress 
    unnecessary flush attempts for read-only operations). - - Note that in a 
    real-life app with multiple transaction proxies, - you will probably want 
    to use parent and child bean definitions - as described in the manual, to 
    reduce duplication. -->

<bean id="SpringHibernateDao"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
        <ref local="transactionManager" />
    </property>
    <property name="target">
        <ref local="HibernateSpringDaoTarget" />
    </property>
    <property name="transactionAttributes">
        <props>
            <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
            <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
            <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
            <prop key="store*">PROPAGATION_REQUIRED</prop>
            <prop key="add*">PROPAGATION_REQUIRED</prop>
        </props>
    </property>
</bean>

Here is the hibernate-cfg.xml file :

          <?xml version="1.0" encoding="UTF-8"?>
         <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
     <hibernate-configuration>
<session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/netprofit</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">test</property>
    <property name="hibernate.connection.autocommit">false</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.format_sql">true</property>
    <property name="hibernate.jdbc.batch_size">50</property>


    <property name="hibernate.c3p0.max_size">1</property>
    <property name="hibernate.c3p0.min_size">0</property>
    <property name="hibernate.c3p0.timeout">5000</property>
    <property name="hibernate.c3p0.max_statements">1000</property>

    <property name="hibernate.c3p0.idle_test_period">300</property>
    <property name="hibernate.c3p0.acquire_increment">1</property>


    <mapping class="com.netprofit.dao.hibernate.HUserRegistrationPojo" />
</session-factory>

Here is the HibDao class (User defined class for simplicity) :

  public class HibDao extends HibernateDaoSupport {
private static final ThreadLocal THREAD = new ThreadLocal();

protected HibDao() {
}

public static Session session() throws Exception {
    Session session = (Session) HibDao.THREAD.get();
    if (session == null) {            
        session = getSessionFactory().openSession();  **--->>>Here how can i open the Session**
        HibDao.THREAD.set(session);
        session().setFlushMode(FlushMode.COMMIT);
    }
    return session;
}

protected static void begin() throws Exception {
    session().beginTransaction();

}

protected static void commit() throws Exception {
    session().getTransaction().commit();
}

protected static void rollback() throws Exception {
    session().getTransaction().rollback();
    session().close();
    HibDao.THREAD.set(null);
}

protected static void flush() throws Exception {
    session().flush();
}

protected static void close() throws Exception {

    session().close();
    HibDao.THREAD.set(null);
}
 }

And after that i just extend the HibDao class and use the begin(), commit() and rollback() method for handling hibernate transaction… and also i am not familiar with Spring……

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-06-01T15:21:53+00:00Added an answer on June 1, 2026 at 3:21 pm

    There is no specific question specified (without the comment line). I read the question like this – “I have injected the SessionFactory bean in xml file. Now, I want to recollect it in a Java program.”

    Simple!

    ApplicationContext context = new FileSystemXmlApplicationContext("c:/../application-hibernate.xml");
    SessionFactory sessionFact = (SessionFactory) context.getBean("sessionFactory");
    

    Now you can do :

    Session session =  sessionFact.openSession();    
    

    Note : I am fetching the bean by directly parsing the xml file, it is not a good practise. In ideal cases you will be fetching ApplicationContext object from request object of Servlet/Action class.

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

Sidebar

Related Questions

Here I am facing a problem that I want to pass a dataset to
i am using AIX OS.here i am facing a problem that when ever the
I herewith a problem that i am facing while implementing PDF file in iPhone.
The problem I’m facing here is that the current regex I created does not
Here I am facing a problem with the displaying of multiple pins at time
I'm facing a problem here, with HttpListener. When a request of the form http://user:password@example.com/
I'm facing a problem of algorithm. Here's the thing : I've got an image
I am facing a problem on developing my web app, here is the description:
Here is my code <body scroll=yes onload=checkWhileOnload(#{Bean.conLimit},'#{Bean.URL}');checkLoadStatus();hideLoader();> The problem i m facing is the
I'm here facing a problem with a Java web project. The project I'm working

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.