[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3917) @NotFound(action=NotFoundAction.IGNORE) results in EAGER loading for @ManyToOne(fetch = FetchType.LAZY) field

Luke Jackson (JIRA) noreply at atlassian.com
Sun Sep 27 23:25:50 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3917?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34066#action_34066 ] 

Luke Jackson commented on HHH-3917:
-----------------------------------

Perhaps this is due to the fact that you cannot proxy a null reference?

The missing object being referred to would not be null, because it would be a proxy instance to an object which you don't know is missing or not, but then on access, when it would be found to be missing, it would have to become null.

> @NotFound(action=NotFoundAction.IGNORE) results in EAGER loading for @ManyToOne(fetch = FetchType.LAZY) field
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-3917
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3917
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.3.1
>            Reporter: Vlasov Igor
>
> Hello 
> I try to use @org.hibernate.annotations.NotFound(action=NotFoundAction.IGNORE) annotation to avoid of throwing an exception IN
> @JoinColumn(name = "UR_ID", referencedColumnName = "UR_ID")
> @ManyToOne(fetch = FetchType.LAZY)
> @org.hibernate.annotations.NotFound(action=NotFoundAction.IGNORE)
> @Basic(optional=true)
>  private UserRole role;
> Then it results me to  EAGER loading  of this field.
> Throw days of debuging  i have found that:
> 1. @org.hibernate.annotations.NotFound results in:
>      isNullable()=true 
> for org.hibernate.type.ManyToOneType
> 2. in org.hibernate.impl.SessionImpl and method internalLoad i can see:
> LoadEventListener.LoadType type = nullable ? 
> 				LoadEventListener.INTERNAL_LOAD_NULLABLE : 
> 				eager ? LoadEventListener.INTERNAL_LOAD_EAGER : LoadEventListener.INTERNAL_LOAD_LAZY;
> Threrefore we have LoadEventListener.INTERNAL_LOAD_NULLABLE  type of loading my relation. !!!
> and in class org.hibernate.event.LoadEventListener.INTERNAL_LOAD_NULLABLE I can see setAllowProxyCreation(false) !!!!
> 3. in org.hibernate.event.def.DefaultLoadEventListener in line 218 there is a condition:
> 	if ( options.isAllowProxyCreation() ) {
> 	return createProxyIfNecessary( event, persister, keyToLoad, options, persistenceContext );
>       }	else {
> 	return load(event, persister, keyToLoad, options);
>     }
> In my case LoadEventListener.INTERNAL_LOAD_NULLABLE.isAllowProxyCreation() ==false !! 
>  and it results in LOADING of Object !!!
> Can we set LoadEventListener.INTERNAL_LOAD_NULLABLE.isAllowProxyCreation() to true ?
> org.hibernate.event.LoadEventListener.INTERNAL_LOAD_NULLABLE = new LoadType("INTERNAL_LOAD_NULLABLE")
> 			.setAllowNulls(true)
> 			.setAllowProxyCreation(false)
> 			.setCheckDeleted(false)
> 			.setNakedEntityReturned(false);

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