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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:43:44+00:00 2026-06-12T13:43:44+00:00

I am facing one problem in Hibernate. Here is the code. Configuration cfg =

  • 0

I am facing one problem in Hibernate. Here is the code.

    Configuration cfg = new Configuration().configure();
    SessionFactory factory = cfg.buildSessionFactory();
    Session session = factory.openSession();

    Transaction trans = session.beginTransaction();
    trans.begin();
    Session session2 = factory.getCurrentSession();
    System.out.println(session2.isConnected());

    trans.commit();

And in my cfg file

  <session-factory>
    <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433</property>
    <property name="hibernate.connection.username">username</property>
    <property name="connection.password">password</property>
    <property name="connection.pool_size">5</property>
    <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="show_sql">true</property>
    <property name="hbm2ddl.auto">false</property>
    <mapping resource="Test.hbm.xml"/>
</session-factory>

when i run the application with above code it is giving me an Exception saying “org.hibernate.HibernateException: isConnected is not valid without active transaction”

I don’t know what behavior its performing internally. Any idea’s please.

  • 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-12T13:43:46+00:00Added an answer on June 12, 2026 at 1:43 pm

    if you look at the Java doc of SessionFactory.html#getCurrentSession

    Obtains the current session. The definition of what exactly “current” means controlled by the CurrentSessionContext impl configured for use.

    So your session and session2 are two different sessions. So you will have to start the transaction on session2 to access isConnected().

    However if you used getCurrentSession() to retrieve first session then second time getCurrentSession() will return you the same instance.

    Session session = factory.getCurrentSession();//Use getCurrentSession rather than openSession
    Transaction trans = session.beginTransaction();
    trans.begin();
    
    Session session2 = factory.getCurrentSession();//Same session will be returned.
    
    System.out.println(session2.isConnected());
    trans.commit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m new to MVC I am facing one problem for finding control of
I am new to winforms and facing one problem in my application. I am
I am facing one problem in the following code , Form is going to
i am using hibernate as ORM tool, i am facing one problem, i need
Im facing one problem in streaming data capture for reading the broadcast data during
We are facing one problem with DownloadStringCompleted method always returning same result in windows
i am facing one problem.i have a class named ReportingService and it should be
I'm developing android application with phonegap . Currently I'm facing one problem with inputbox
I am learning OpenCV using Learning OpenCV book. One problem I am facing while
I am facing a problem in accessing the mysql DB on one of my

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.