[hibernate-issues] [Hibernate-JIRA] Resolved: (ANN-725) @OneToOne: optional = true is ignored

Emmanuel Bernard (JIRA) noreply at atlassian.com
Sat May 31 15:08:33 EDT 2008


     [ http://opensource.atlassian.com/projects/hibernate/browse/ANN-725?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bernard resolved ANN-725.
----------------------------------

    Resolution: Rejected

This is not what optional means. Optional is closer to FK columns being nullable or not.
You want to use @NotFound




> @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