7 Replies Latest reply: Dec 23, 2010 7:32 AM by Andrei Zagorneanu RSS

ObjectNotFoundException for an audited optional association.

Andrei Zagorneanu Newbie

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.