[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5808) ObjectNotFoundException for an audited optional association. Envers is creating a proxy even when the association is null.

Andrei Zagorneanu (JIRA) noreply at atlassian.com
Mon Jan 24 03:37:05 EST 2011


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5808?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39753#action_39753 ] 

Andrei Zagorneanu commented on HHH-5808:
----------------------------------------

Call the getter for the association inside a try/catch block and in case of an exception assign a null to the association.

> ObjectNotFoundException for an audited optional association. Envers is creating a proxy even when the association is null.
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-5808
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5808
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: envers
>    Affects Versions: 3.6.0
>         Environment: Hibernate 3.6.0.Final, reproducible on Oracle and H2 with both EntityManager and Session
>            Reporter: Andrei Zagorneanu
>            Assignee: Adam Warski
>         Attachments: TestCase-Optional-Unidirectional-OneToOne.zip
>
>
> 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 I can see that Address is not null, instead Envers is creating a proxy for it. When I'm trying to access that Address proxy 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 at 143fd2a[
>   id=<null>
>   ver=<null>
> ]]
> I have to use composite PK because Address is a legacy table.
> I posted this issue on Envers forum: http://community.jboss.org/thread/159906?tstart=0
> The issue is reproducible while working with EntityManager and as well with Session.
> I attached a TestNG test case for this.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list