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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:24:46+00:00 2026-06-02T17:24:46+00:00

Note: This question is related for my previous one . I am using hibernate.current_session_context_class=thread

  • 0

Note: This question is related for my previous one.

I am using hibernate.current_session_context_class=thread in my Hibernate configuration and getting Hibernate sessions via SessionFactory.getCurrentSession() as needed. So it does create or give me existing sessions when needed, so I do not take care of this.

This is all great, but what to do when I do get a HibernateException, a ConstraintViolationException for example? Then the current session I acquired before becomes invalid and I cannot use it anymore, not even for reading out some more data (according to many forums I’ve read). How can I discard and get then the new session within particular scope? I think calling SessionFactory.getCurrentSession() for the 2nd time still will return me the same invalid session!?

  • 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-02T17:24:47+00:00Added an answer on June 2, 2026 at 5:24 pm

    For the ThreadLocalSessionContext, the session will be closed when the transaction finsihes. So in this case you should call tx.rollback(), then sessionFactory.getCurrentSession() to start afresh.

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

Sidebar

Related Questions

Note: this question is related to this one , but two years is a
I’m using Drupal (please note that this is not a Drupal related question), and
This question is related to this previous one on how to replace accented strings
Please note this question related to performance only. Lets skip design guidelines, philosophy, compatibility,
Note: This question is related to an advice rather than an issue. I would
Note: This question has broadened in scope from previous revisions. I have tried to
Note: In this question I'm using the term autocomplete (or iterative search) to refer
Although slightly related to a previous question, it is different. How secure is this
NOTE: This question is related to CodeIgniter-RestServer When I call model.save() from backbone the
NOTE: This question is only loosely related to tinyxml, however including details like that

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.