[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3853?page=c...
]
Shawn Clowater commented on HHH-3853:
-------------------------------------
This is as good a place as any to throw my 2 cents in. This appears to have broken during
the fix of HHH-5109. Under that change the AnnotationBinder was changed from
final boolean mandatory = !ann.optional() || forcePersist;
to final boolean mandatory = !ann.optional() || forcePersist || trueOneToOne;
which essentially forces the association to mandatory regardless of whether or not it is
specified as optional or not.
I've managed to get it to work by changing the @PrimaryKeyColumn on the owning side to
a OneToOne(mappedBy) reference but I suspect that may have some other effect down the line
for me although it looks like using the mappedBy will do the same thing eventually in the
case of the OneToOne mapping except that it appears I'll take an extra hit on
SessionFactory configuration time.
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