[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3853?page=c...
]
Duncan Kinnear commented on HHH-3853:
-------------------------------------
We are having the same problem with annotations in 3.5.4.
We just upgraded to 3.5.4 from 3.3.2 (Core).
We have an entity class called PerOrg (short for Person/Organisation) which has
relationships to several optional 'role' entities. These relationships are
one-to-one based on the primary key (an assigned string 'id').
Each relationship is defined in the 'PerOrg' class similar to the following:
@OneToOne(fetch = FetchType.EAGER, optional = true)
@PrimaryKeyJoinColumn
@Updated
private Supplier supplier;
In the previous version of Hibernate, this was fine, but with the new version the schema
update fails because it tries to add a foreign key constraint between PerOrg and the
related roles. Of course this fails because no PerOrg has ALL the roles associated with
it.
We have reverted the version of Hibernate back for just now, but we'd like to know why
this is happening in the new version.
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
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