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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:48:19+00:00 2026-05-16T23:48:19+00:00

I am trying to persist the entity with constraint validation, when invoke persist –

  • 0

I am trying to persist the entity with constraint validation,
when invoke persist – there is constraint that thrown and the caller get EjbTransactionRolledbackException…
so I try to call the validation explicit and throw ConstraintViolationException/RuntimeException and still the caller get EjbTransactionRolledbackException…
when I throw MyException extends Exception – the caller get MyException

Even when I call explicit sc.setRollBackOnly it’s still happened 🙁

This shouldn’t be the behavior.

what’s going on?

Configuration:

Netbeans 6.9.1
Glassfish 3.0.1
JPA 2.0 (EclipseLink)
EJB 3.1

Thanks!!!

@Stateless
public class My {

@PersistenceContext
EntityManager em;

@Resource
Validator  validator;

public Order checkout(Order order) {
    Set<ConstraintViolation<Order>> set = validator.validate(order, Default.class);

    if (!set.isEmpty()) {
        sc.setRollbackOnly();
        //throw new ConstraintViolationException(new HashSet<ConstraintViolation<?>>(set));
        throw new RuntimeException();
    }

    this.em.persist(order);
}
  • 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-05-16T23:48:19+00:00Added an answer on May 16, 2026 at 11:48 pm

    so I try to call the validation explicit and throw ConstraintViolationException/RuntimeException and still the caller get EjbTransactionRolledbackException…

    Providing the full stacktrace might help. Anyway, I wonder how you are calling your EJB and if you’re propagating a transaction, in which case throwing a EJBTransactionRolledbackException is the right behavior in case of a system exception. But the following blog post might help:

    Constraint violated, transaction rolled back

    When using bean validation on JPA
    entities within an EJB 3 bean you
    would actually get an
    EJBTransactionRolledbackException if
    there is a constraint violation.

    javax.ejb.EJBTransactionRolledbackException: Invalid object at persist time for groups [javax.validation.groups.Default, ]
    Caused by: javax.validation.ConstraintViolationException: Invalid object at persist time for groups [javax.validation.groups.Default, ]
    

    This is all nicely according to
    specification, but not really
    interesting information. You don’t
    really want to know what happened, you
    want to know what went wrong.

    So I recommend adding the following to
    your ejb-jar.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <ejb-jar
            xmlns="http://java.sun.com/xml/ns/javaee"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                                http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
            version="3.0">
       <assembly-descriptor>
          <application-exception>
             <exception-class>javax.validation.ConstraintViolationException</exception-class>
             <rollback>true</rollback>
          </application-exception>
       </assembly-descriptor>
    </ejb-jar>
    

    That way you can directly access your
    violations.

    Resources

    • On EJB and application vs system exception:
      • Best practices in EJB exception handling
      • 16.6. Exceptions and Transactions
    • On Bean Validation
      • Constraint violated, transaction rolled back
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.