[hibernate-issues] [Hibernate-JIRA] Commented: (ANN-725) @OneToOne: optional = true is ignored
Adrian Moos (JIRA)
noreply at atlassian.com
Tue Apr 15 12:51:34 EDT 2008
[ http://opensource.atlassian.com/projects/hibernate/browse/ANN-725?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30000 ]
Adrian Moos commented on ANN-725:
---------------------------------
The following patch fixes the bug:
Index: AnnotationBinder.java
===================================================================
--- AnnotationBinder.java (revision 11282)
+++ AnnotationBinder.java (working copy)
@@ -1839,7 +1839,7 @@
}
defineFetchingStrategy( value, inferredData.getProperty() );
//value.setFetchMode( fetchMode );
- value.setIgnoreNotFound( ignoreNotFound );
+ value.setIgnoreNotFound( ignoreNotFound || optional );
value.setCascadeDeleteEnabled( cascadeOnDelete );
//value.setLazy( fetchMode != FetchMode.JOIN );
if ( !optional ) {
> @OneToOne: optional = true is ignored
> -------------------------------------
>
> Key: ANN-725
> URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-725
> Project: Hibernate Annotations
> Issue Type: Bug
> Components: binder
> Affects Versions: 3.3.0.ga
> Environment: hibernate 3.2.4.sp1
> Reporter: Adrian Moos
> Priority: Minor
>
> In some entity, I map:
> @javax.persistence.OneToOne(targetEntity = InfoAutoVerrechnungImpl.class, fetch = FetchType.LAZY, //
> optional = true)
> @javax.persistence.JoinColumns(/**/{
> @javax.persistence.JoinColumn(name = "MI0153A", referencedColumnName = "MI0153A", //
> nullable = false, updatable = false, insertable = false),
> @javax.persistence.JoinColumn(name = "MI1997A", referencedColumnName = "MI1997A", //
> nullable = false, updatable = false, insertable = false) })
> public InfoAutoVerrechnung getInfoAutoVerrechnung();
> The optional = true is lost during construction of hibernate's configuration metamodel, as the property is represented using a ManyToOneType (!) with ignoreNotFound == false (and hence nullable == false). Consequently, hibernate installs a proxy for the property on entity load even if the remote end of the association does not exist (whose lazy initialization fails with an ObjectNotFoundException).
> Expected behavior: Hibernate should either respect the optional = true, or throw a MappingException (ideally mentioning the expected way to express nullability).
> Workaround: Adding
> @NotFound(action = NotFoundAction.IGNORE)
> causes hibernate to treat the property as nullable.
--
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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list