Uploaded image for project: 'Hibernate ORM'
  1. Hibernate ORM
  2. HHH-8028

entityManager.persist not throwing ConstraintValidationException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 4.2.0.CR1
    • Fix Version/s: None
    • Environment:
      Hibenate 4.2.0-RC1
      HibernateValidator 4.3.1.Final
      H2 in memory database 1.3.170
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true

      Description

      While trying to persist an entity with:

      • an id generated with strategy GenerationType.TABLE
      • a field annotated with @javax.validation.constraints.NotNull
      • a null value for that field

      I was expecting that:

      • the entityManager.persist() throws a javax.validation.ConstraintViolationException
      • the transaction to be marked as rollback-only
        (Those expectations are based on jpa 2.0 specifications)

      But the current behavior is:

      • entityManager.persist() don't throw any exception
      • transaction is not marked as rollback only
      • later, the transaction.commit() throws a RollbackException

      Remarks:

        Issue Links

          Activity

          Hide
          harshappt harsha puthalapattu added a comment -

          Same issue happens even when the id is generated with jpa- sequence generator. However, works fine when @GeneratedValue(strategy=GenerationType.IDENTITY) and @GeneratedValue(strategy=GenerationType.AUTO) are used.

          I wonder if it is something wrong with our code. Any help would be greatly appreciated.

          Show
          harshappt harsha puthalapattu added a comment - Same issue happens even when the id is generated with jpa- sequence generator. However, works fine when @GeneratedValue(strategy=GenerationType.IDENTITY) and @GeneratedValue(strategy=GenerationType.AUTO) are used. I wonder if it is something wrong with our code. Any help would be greatly appreciated.
          Hide
          hardy.ferentschik Hardy Ferentschik added a comment -

          The problem is that em.persist is not calling the pre-persist callbacks. Hibernate delays the execution of these callbacks until em.flush() is called. Even though this might sound counterintuative initially, it makes more sense if you think about whole object graphs and cascading operations. Flush is when Hibernate ORM identifies all the entities that have been changed and need database actions.

          Regarding the spec, it is vague enough in this regards to allow for this behaviour.

          Show
          hardy.ferentschik Hardy Ferentschik added a comment - The problem is that em.persist is not calling the pre-persist callbacks. Hibernate delays the execution of these callbacks until em.flush() is called. Even though this might sound counterintuative initially, it makes more sense if you think about whole object graphs and cascading operations. Flush is when Hibernate ORM identifies all the entities that have been changed and need database actions. Regarding the spec, it is vague enough in this regards to allow for this behaviour.
          Show
          hardy.ferentschik Hardy Ferentschik added a comment - See also http://hibernate.org/validator/faq/#why-is-my-jpa-entity-not-validated-when-i-call-persist
          Hide
          brmeyer Brett Meyer added a comment -

          Bulk closing rejected tickets in "resolved" state.

          Show
          brmeyer Brett Meyer added a comment - Bulk closing rejected tickets in "resolved" state.

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development