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
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@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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira