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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:04:11+00:00 2026-06-10T14:04:11+00:00

i am working with stateless session for batch job in my Play Framework 1.2.4

  • 0

i am working with stateless session for batch job in my Play Framework 1.2.4 project.

i am inserting and updating rows quite good, but i dont know what to do when an exception occured. Heres my code:

try{
      statelesssession.insert(someobject);
   }
catch(ConstraintViolationException e)  //It happens from time to time dont ask me why..
   {
      ??????transaction.rollback();????? THATS MY CONCERN
   }
finally{
      transaction.commit();
   }

What i need to know is, i am committing data at every 100 inserts. i am wondering, if constraintviolation happens in i.e 56th record and transaction does the rollback, will i lose the other 55 records too?

if yes, what do i have to do in constraintviolationexception? or shall i commit in every 1 record to avoid this?

  • 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-10T14:04:12+00:00Added an answer on June 10, 2026 at 2:04 pm

    If you commit every 100 inserts, then a rollback after the 56th insert also undos all 55 inserts before.

    You can commit after every insert, but in batches who insert really many rows that is slow and so not recommended.

    The solution is using savepoints.

    Setting a savepoint is relatively fast. It can be done after every insert. Setting a savepoint does not write any data into the database – you still have to commit later – but a rollback only is done until the last savepoint.

    So in your example you commit every 100 (or whatever) rows (and after the last row for sure), and you set a savepoint after every row. When an error appears and you roll back the action, only the errorneous insert is undone, the others are not touched.

    For a description see for example java.sql.Connection.setSavepoint, java.sql.Savepoint or here.

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

Sidebar

Related Questions

Working on a project using Entity Framework (4.3.1.0). I'm trying to figure out how
I'm working on a large legacy application using stateless session beans that has recently
I am working on an EJB3 application with mainly stateless session beans (SLSB). They
Working on the problems on Project Euler to try to learn Clojure. I'm on
Is it possible to access a stateful session bean inside a stateless bean? My
I'm implementing stateless session bean ejb3 in glassfish server using netbeans. First time, it
I'm working on modifying an existing application implemented as a 2.1 stateless EJB. I'd
I'm working on .Net project (windows service) and I found memory leak. Using ANTS
I was hoping that changing into create-session=stateless would be the end of it to
Consider this simplified view of some code with which I'm working: @Stateless(...) @Remote(...) @TransactionAttribute(TransactionAttributeType.MANDATORY)

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.