[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3853?page=c...
]
Fabio adriano Lisboa Gomes commented on HHH-3853:
-------------------------------------------------
Up to version 3.5.3 of Hibernate, OneToOne optional relationships based on primary key
functioned perfectly.
From version 3.5.4,3.5.5 and 3.5.6, hibernate tries to load all
associations, even if they do not exist, resulting in the error below
*org.hibernate.ObjectNotFoundException: No row with the given identifier exists*
Following model that illustrates the problem. A person can be a professor or student or
both.
public class Person
{
@OneToOne (cascade = CascadeType.ALL, optional = true)
@PrimaryKeyJoinColumn
@Nullable
public getProfessor Professor(){
return teacher;
}
@OneToOne (cascade = CascadeType.ALL, optional = true)
@PrimaryKeyJoinColumn
@Nullable
public Alumnus getStudent(){
return student;
}
}
A workaround is to assign empty objects when person has no role.
one-to-one mapping doesn support Primary Key Association
--------------------------------------------------------
Key: HHH-3853
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3853
Project: Hibernate Core
Issue Type: Bug
Components: envers
Environment: Hibernate - core 3.4.0-SNAPSHOT, Hibernate - envers (trunk build
from today)
Reporter: Amar Singh
Assignee: Adam Warski
Attachments: one-to-one-pk.zip
one-to-one mapping with primary key association doesn't seem to be working. Eg.
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="org.hibernate.envers.test.integration.onetoone.bidirectional"
default-lazy="false">
<class name="BidirectionalRefIngPK"
table="BIDIRECTIONAL_REFERENCING_ENTITY">
<id name="id" type="long"
column="BIDIRECTIONAL_REFERENCING_ID" >
<generator class="foreign">
<param name="property">reference</param>
</generator>
</id>
<property name="data"/>
<property column="BIDIRECTIONAL_REFERENCING_ID"
generated="never" insert="false" lazy="false"
name="id" type="long" update="false"/>
<one-to-one name="reference" cascade="save-update"
class="BidirectionalRefEdPK" constrained="true" />
</class>
<class name="BidirectionalRefEdPK"
table="BIDIRECTIONAL_REFERENCED_ENTITY">
<id name="longId" type="long"
column="BIDIRECTIONAL_REFERENCED_ID">
<generator class="native"/>
</id>
<property name="data"/>
<one-to-one name="referencing" cascade="all"
class="BidirectionalRefIngPK" />
</class>
</hibernate-mapping>
When we try to load a BidirectionalRefIngPK, the underlying query invokes
RelatedAuditExpression and since its not a foreign-key based one-to-one association the
loading fails in method addToQuery of RelatedAuditExpression at line 52
(relatedEntity==null) with the following exception:
Code:
"This criterion can only be used on a property that is a relation to another
property."
TO REPRODUCE
~~~~~~~~~~~~~
Please find a zip file attached which has four files:
- BidirectionalPrimaryAssociation.java (actual testng test case)
- BidirectionalRefEdPK.java (Entity 1)
- BidirectionalRefIngPK.java (Entity 2)
- mappings.hbm.xml
Please put the three java files in its package
(org.hibernate.envers.test.integration.onetoone.bidirectional) and the mapping file in
src/test/resources.
Now when you run envers tests you should see the failure.
Thanks for this great component !
--
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