[hibernate-dev] HHH-8670 another EntityManager.find() not returning null question

Scott Marlow smarlow at redhat.com
Tue Nov 5 11:18:03 EST 2013


On 11/05/2013 05:13 AM, Sanne Grinovero wrote:
> On 5 November 2013 00:20, Scott Marlow <smarlow at redhat.com> wrote:
>> HHH-8670 is about EntityManager.find() not returning null when a runtime
>> exception is caught when performing the find().  Returning null when a
>> ClassCastException (or any other runtime exception) occurs seems
>> confusing to me, but I suppose that we could log a DEBUG warning (like
>> we did for EntityNotFoundException).
>>
>> Does anyone disagree with changing Hibernate ORM to return null when a
>> runtime exception is caught during the EntityManager.find() operation?
>
> I would disagree yes, seems wrong. A failure is a failure, a null
> would imply the entity doesn't exist which is misleading.
> Shouldn't it simply throw the runtime exception?
> And ideally fix the ClassCastException to not ever happen? I might
> have misunderstood how that is happening: the way you describe it I
> got the impression that there's a bug in ORM, but even if this was a
> user mistake, by changing this semantic you wouldn't give the
> opportunity to the user to fix his code.

Thanks for the feedback Sanne.  In my current case that I am exploring, 
the RuntimeException is not actually a CCE but it could of been.

Its actually an org.hibernate.exception.GenericJDBCException => 
java.sql.SQLException => javax.resource.ResourceException => 
javax.resource.ResourceException.

>
> Sanne
>
>>
>> Scott
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev



More information about the hibernate-dev mailing list