I think that there is a bug in CMR...
pol.leleux Oct 1, 2002 10:11 AMHello all,
I have a table with 2 FK's (one is mandatory, the other is not, i.e. the first cannot be null while the second can).
I created an entity bean with CMR relationships to the 2 foreign objects
I wrote a finder which could look like this :
@ejb:finder signature="java.util.Collection findByObj1AndObj2( Obj1 obj1, Obj2 obj2)"
query="SELECT OBJECT(o) FROM Schema o WHERE o.obj1 = ?1 AND o.obj2 = ?2"
the goal of that finder is to find all objects with given values for the foreign keys.
While it works if I call it with something like this :
findByObj1AndObj2( obj1, obj2 ) where obj1 != null && obj2 != null,
it fails with the following exception if I use something like this :
findByObj1AndObj2( obj1, null ) where obj1 != null
which I would use to find all objects that have a relation with obj1 but no relation in the second foreign key
=========================================================
15:12:35,022 ERROR [STDERR] javax.ejb.FinderException: Find failed: java.lang.Nu
llPointerException
15:12:35,022 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractQu
eryCommand.execute(JDBCAbstractQueryCommand.java:143)
15:12:35,022 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCFindEntiti
esCommand.execute(JDBCFindEntitiesCommand.java:40)
15:12:35,022 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManag
er.findEntities(JDBCStoreManager.java:472)
15:12:35,022 ERROR [STDERR] at org.jboss.ejb.plugins.CMPPersistenceManager.f
indEntities(CMPPersistenceManager.java:348)
15:12:35,052 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedCo
nnectionInterceptor.findEntities(CachedConnectionInterceptor.java:323)
15:12:35,052 ERROR [STDERR] at org.jboss.ejb.EntityContainer.findLocal(Entit
yContainer.java:610)
15:12:35,052 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor217.invoke
(Unknown Source)
15:12:35,052 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
15:12:35,052 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:3
24)
15:12:35,052 ERROR [STDERR] at org.jboss.ejb.EntityContainer$ContainerInterc
eptor.invokeHome(EntityContainer.java:1116)
15:12:35,052 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractInterceptor.inv
okeHome(AbstractInterceptor.java:73)
15:12:35,052 ERROR [STDERR] at org.jboss.ejb.plugins.EntitySynchronizationIn
terceptor.invokeHome(EntitySynchronizationInterceptor.java:257)
15:12:35,052 ERROR [STDERR] at org.jboss.resource.connectionmanager.CachedCo
nnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:215)
15:12:35,052 ERROR [STDERR] at org.jboss.ejb.plugins.EntityInstanceIntercept
or.invokeHome(EntityInstanceInterceptor.java:134)
15:12:35,052 ERROR [STDERR] at org.jboss.ejb.plugins.EntityLockInterceptor.i
nvokeHome(EntityLockInterceptor.java:79)
15:12:35,052 ERROR [STDERR] at org.jboss.ejb.plugins.EntityCreationIntercept
or.invokeHome(EntityCreationInterceptor.java:44)
15:12:35,052 ERROR [STDERR] at org.jboss.ejb.plugins.AbstractTxInterceptor.i
nvokeNext(AbstractTxInterceptor.java:98)
15:12:35,062 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.runWit
hTransactions(TxInterceptorCMT.java:167)
15:12:35,062 ERROR [STDERR] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke
Home(TxInterceptorCMT.java:52)
15:12:35,062 ERROR [STDERR] at org.jboss.ejb.plugins.SecurityInterceptor.inv
okeHome(SecurityInterceptor.java:104)
15:12:35,062 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.invokeHo
me(LogInterceptor.java:109)
15:12:35,062 ERROR [STDERR] at org.jboss.ejb.EntityContainer.invokeHome(Enti
tyContainer.java:487)
15:12:35,062 ERROR [STDERR] at org.jboss.ejb.plugins.local.BaseLocalContaine
rInvoker.invokeHome(BaseLocalContainerInvoker.java:227)
15:12:35,062 ERROR [STDERR] at org.jboss.ejb.plugins.local.LocalHomeProxy.in
voke(LocalHomeProxy.java:110)
15:12:35,062 ERROR [STDERR] at $Proxy288.findByAppAndEntityPage(Unknown Sour
ce)
==========================================================
I think that it should work. Is there anyway to make it work ?
To bypass the problem, I wrote a finder using the first foreign key only, then I filtrate the results by eliminating all the records which have the second foreign object not null which is far from being the nicest solution !