[hibernate-issues] [Hibernate-JIRA] Commented: (EJB-249) Query.getResultList() throws undocumented EntityNotFoundException

Koda Janh (JIRA) noreply at atlassian.com
Tue Nov 14 22:39:04 EST 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/EJB-249?page=comments#action_25292 ] 

Koda Janh commented on EJB-249:
-------------------------------

Emmanuel,

The main point of the bug report was not that Hibernate should give a less misleading exception but rather that it should throw only the declared exceptions according to the specification. Two alternatives are:

1) Hibernate catches EntityNotFoundException in getResultList() and returns an empty list instead (seems to best choice from a specification point of view, but harder to debug problems), or
2) Hibernate wraps the EntityNotFoundException using IllegalStateException which is declared by the specification (easier to debug problems but IllegalStateException wasn't strictly designed for this sort of exceptional case)

What do you think?

> Query.getResultList() throws undocumented EntityNotFoundException
> -----------------------------------------------------------------
>
>          Key: EJB-249
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-249
>      Project: Hibernate Entity Manager
>         Type: Bug

>   Components: EntityManager
>     Versions: 3.2.0.ga
>     Reporter: Koda Janh
>  Attachments: stacktrace.txt
>
>
> I am issuing the query: "select user from " + User.class.getName() + " as user"
> and I am getting this stack-trace:
> javax.persistence.EntityNotFoundException: Unable to find mobi.database.domain.Server with id 249
>      at org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound(Ejb3Configuration.java:107)
>      at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:143)
>      at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:193)
>      at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:101)
>      at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
>      at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:846)
>      at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
>      at org.hibernate.type.EntityType.resolve(EntityType.java:303)
>      at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
>      at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
>      at org.hibernate.loader.Loader.doQuery(Loader.java:717)
>      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
>      at org.hibernate.loader.Loader.doList(Loader.java:2144)
>      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
>      at org.hibernate.loader.Loader.list(Loader.java:2023)
>      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
>      at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
>      at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
>      at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
>      at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
>      at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
> I've tracked down the problem to a "@Column(nullable=false)". Specifically, if one of the objects in the result-set contain a null field that is defined as "nullable=false" then the above exception will occur.
> This behavior should either be documented in the Javadoc or the implementation should be changed to throw one of the declared exceptions instead. Also, the actual error message is misleading in that the specified object *is* found, but it violates the constraints of the ORM mapping.

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