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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:39:16+00:00 2026-06-16T05:39:16+00:00

I wonder what is the best way to catch an OptimisticLockException in JavaEE 6.

  • 0

I wonder what is the best way to catch an OptimisticLockException in JavaEE 6. I have the following EJB:

@Stateless
public class SeminarBooking {

public void bookSeminar(Long seminarId, int numberOfPersons) {
    ...
    //check capacity & do booking
    //OptimisticLockException can occur in this method
}

And this is my REST interface:

@Path("/seminars")
@Produces("application/xml")
@Stateless
public class SeminarResource {

    @GET
    @Path("{id}/book")
    public Seminar bookSeminar(@PathParam("id") Long id, @QueryParam("persons") Integer persons) {
        try {
            seminarBooking.bookSeminar(id, persons);
            return seminarBooking.getSeminar(id);
        }
        catch(Exception e) {
            //why is this never called?
            logger.error(This will never happen, e);
            throw new WebApplicationException(e);
        }
}

In the REST interface I catch all Exceptions, furthermore I see the OptimisticLockException if I call the interface from the browser, so why is the catch-Block never executed?

  • 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-16T05:39:18+00:00Added an answer on June 16, 2026 at 5:39 am

    The obvious answer is that the exception in question isn’t raised within that try block. Try reading the stack trace to see where it’s thrown from. Given that it’s related to persistence, it’s likely thrown at your transaction boundary rather than from where you think it is.

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

Sidebar

Related Questions

I always wonder about the best way to access a class attribute from a
I have this question a while back. Just wonder what is the best way
I wonder what is the best way to do this. I have two menues
I just wonder what's the best way to apply a function that returns Void
I wonder how is the best way to integrate Java modules developed as separate
I wonder that what is the best way of writing a component for joomla
I wonder which method among the following three methods is the best to perform
wonder whether someone can help me with the following one... I have a struct
I wonder - what is the best way to supply contextual (i.e. not related
wonder if I could get some advice on the best way to solve this

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.