[
http://opensource.atlassian.com/projects/hibernate/browse/EJB-249?page=co...
]
Koda Janh commented on EJB-249:
-------------------------------
Notice the last SQL query in the log is:
select server0_.id as id1_1_, server0_.hostId as hostId1_1_, server0_.port as port1_1_,
server0_.shutdownRequested as shutdown3_1_1_, server0_.running as running1_1_, host1_.id
as id0_0_, host1_.name as name0_0_, host1_.shutdownRequested as shutdown3_0_0_ from
servers server0_ inner join hosts host1_ on server0_.hostId=host1_.id where
server0_.id=316
and when I run this query manually this yields an empty set for me too. But (!!) if you
take out the inner join on servers.hostId you get back the results as expected, so I think
this explains what is going on. Hibernate's use of the inner join implicitly assumes
that servers.hostId is not null (which it actually is for my case) and so it gets back an
empty set which it isn't expecting and so it throws an exception. The problem is
that:
The User exists, the Server it references exists but the Host that the Server references
does not (because Server.host is null).
Class server defines the following relationship:
@ManyToOne
@JoinColumn(name="hostId", nullable=false)
private Host host;
so again Hibernate is being told that hostId is not supposed to ever be null but it
actually is.
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira