Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2279

Merge Validation Fails With Chained Constructor

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.0
    • Fix Version/s: None
    • Component/s: validation
    • Labels:
      None
    • Environment:
      java 1.6

      Description

      The following simple test fails

      em.merge(new Customer("Park Lane");

      when there is a chained constructor and validation like this:

      public Customer()

      { this(null); }

      public Customer(String street)

      { address = new Address(); address.street = street; // annotated @NotNull }

      OpenJPA validation is calling the first constructor during merge or validation
      and is trying to validate an invalid object, even though the orginal WAS valid.

      The stacktrace is

      Caused by: javax.validation.ConstraintViolationException: A validation constraint failure occurred for class "testcase.openjpa.Address".
      at org.apache.openjpa.persistence.validation.ValidatorImpl.validate(ValidatorImpl.java:282)
      at org.apache.openjpa.validation.ValidatingLifecycleEventManager.fireEvent(ValidatingLifecycleEventManager.java:123)
      at org.apache.openjpa.kernel.BrokerImpl.fireLifecycleEvent(BrokerImpl.java:800)
      at org.apache.openjpa.kernel.BrokerImpl.persistInternal(BrokerImpl.java:2635)
      at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2571)
      at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2554)
      at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2544)
      at org.apache.openjpa.kernel.SingleFieldManager.persist(SingleFieldManager.java:272)
      at org.apache.openjpa.kernel.StateManagerImpl.cascadePersist(StateManagerImpl.java:3045)
      at org.apache.openjpa.kernel.BrokerImpl.persistInternal(BrokerImpl.java:2670)
      at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2571)
      at org.apache.openjpa.kernel.AttachStrategy.persist(AttachStrategy.java:95)
      at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:102)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:252)
      at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:105)
      at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3474)
      at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1214)
      at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:878)
      at testcase.openjpa.OpenJpaTest.testValidation(OpenJpaTest.java:20)

        Attachments

        1. openjpa-2279.tar.gz
          3 kB
          Roger Keays

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rogerkeays Roger Keays
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: