7 Replies Latest reply on Dec 23, 2010 7:32 AM by azagorneanu

    ObjectNotFoundException for an audited optional association.

    azagorneanu

      Hi,

       

      I have a Contact entity which has an optional unidirectional 1:1 association with an Address entity. Now, when I'm retrieving a version of Contact which doesn't have an Address from audit tables and trying to access the Address I'm getting: org.hibernate.ObjectNotFoundException: No row with the given identifier exists

       

      This is my entity class:

      @Entity

      @Audited

      public class Contact {

           // some fields

           private Address address;

       

           @OneToOne(cascade = { CascadeType.ALL }, orphanRemoval = true)

           @JoinColumns( {
                  @JoinColumn(name = "ID_ADDRESS", referencedColumnName = "ID_ADDRESS"),
                  @JoinColumn(name = "VER_ADDRESS", referencedColumnName = "VER_ADDRESS") })

           public Address getAddress() {
              return this.address;
          }

       

      Now when I'm retrieving a Contact revision:

           AuditReader reader = AuditReaderFactory.get(session);
           Contact contact = reader.find(Contact.class, id, revision);

           // here address is not null

           Address address = contact.getAddress();

           // here I'm getting org.hibernate.ObjectNotFoundException

           address.getId();

       

      The exception which I'm getting:

      org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.acme.model.address.Address#com.acme.model.address.AddressPK@143fd2a[
        id=<null>
        ver=<null>
      ]]

       

      I found the following issue related to composite PK and @OneToOne opened in JIRA: HHH-5343 (Issue with lazy loading of composite key for 1:1 entity relationships). Maybe it's related to the same issue.

       

      Please advice.

      Thanks.

        • 1. Re: ObjectNotFoundException for an audited optional association.
          azagorneanu

          Does anybody know what is the problem? Some hints, suggestions?

           

          Should I open a JIRA bug for this?

           

          Please help.

          • 2. Re: ObjectNotFoundException for an audited optional association.
            0x3333

            Hi!

             

            I'm having the same issue here. In my case it's related to the N:1 relationship.

             

            I have a Customer entity and this customer has a N:1 relationship with CustomerType, when I load a revision of Customer and try to get the CustomerType I get an exception:

             

            Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [br.com.unimaquina.erp.dynamic.MtProduto#23]
            at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:433)
            at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:189)
            at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:178)
            at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)
            at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)

            Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.john.doe.Customer#23]

            at org.hibernate.impl.SessionFactoryImpl$2.handleEntityNotFound(SessionFactoryImpl.java:433)

            at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:189)

            at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:178)

            at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)

            at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)

             

            I think that this is a bug, I'll try to file a bug, but JIRA is down now.

            • 3. Re: ObjectNotFoundException for an audited optional association.
              azagorneanu

              Ok. In case you will open a bug for this, just post the JIRA bug number here, to have it as a reference.

              • 4. Re: ObjectNotFoundException for an audited optional association.
                fbascheper

                Hi,

                 

                Have you verified that the row actually exists in the database (i.e. after the transaction has completed)?

                If so, please provide a working testcase against the envers testsuite.

                 

                Regards,

                Erik-Berndt

                • 5. Re: ObjectNotFoundException for an audited optional association.
                  azagorneanu

                  The row doesn't exists in DB because this is an optional 1:1 association. A Contact can have or can not have an Address. The Address is optional. If Contact has an address then everything is OK. In case the Contact doesn't have an Address, then while retrieving a revision for this Contact from audit tables the ObjectNotFoundException is raised when the contact address is accessed. In this case the address should be null, but instead Envers creates a proxy and tries to initialize it.

                  • 6. Re: ObjectNotFoundException for an audited optional association.
                    fbascheper

                    This looks like a bug. Could you open a Jira issue with a reproducible (TestNG) testcase?

                    • 7. Re: ObjectNotFoundException for an audited optional association.
                      azagorneanu

                      I created a JIRA bug for this with an attached TestNG testcase. This is the link: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5808