-
1. Re: Problem with remove() URGENT!!!
optimusprime Oct 27, 2004 6:49 PM (in response to optimusprime)Could someone please help me. I really need help on this
Thanks -
2. Re: Problem with remove()
raist_majere Oct 27, 2004 10:39 PM (in response to optimusprime)Can you provide the stack trace of this exception, as well as the source code of ejbRemove of the implied beans and the ejb-jar.xml file, please? That could help...
-
3. Re: Problem with remove()
optimusprime Oct 28, 2004 8:42 AM (in response to optimusprime)<ejb-relation> <ejb-relation-name>bancoProjeto-projetoConfiguraDados</ejb-relation-name> <ejb-relationship-role> <description>bancoProjeto</description> <ejb-relationship-role-name>BancoProjetoRelationshipRole</ejb-relationship-role-name> <multiplicity>One</multiplicity> <relationship-role-source> <description>bancoProjeto</description> <ejb-name>BancoProjeto</ejb-name> </relationship-role-source> <cmr-field> <description>projetoConfiguraDados</description> <cmr-field-name>projetoConfiguraDados</cmr-field-name> <cmr-field-type>java.util.Collection</cmr-field-type> </cmr-field> </ejb-relationship-role> <ejb-relationship-role> <description>projetoConfiguraDados</description> <ejb-relationship-role-name>ProjetoConfiguraDadosRelationshipRole</ejb-relationship-role-name> <multiplicity>Many</multiplicity> <relationship-role-source> <description>projetoConfiguraDados</description> <ejb-name>ProjetoConfiguraDados</ejb-name> </relationship-role-source> </ejb-relationship-role> </ejb-relation> java.sql.SQLException: ERROR: ExecUpdate: Fail to add null value in not null attribute id_banco_projeto at org.postgresql.core.QueryExecutor.executeV2(QueryExecutor.java:289) at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:105) at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:43) at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:515) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:50) at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:271) at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:324) at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.execute(JDBCStoreEntityCommand.java:136) at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.storeEntity(JDBCStoreManager.java:627) at org.jboss.ejb.plugins.CMPPersistenceManager.storeEntity(CMPPersistenceManager.java:421) at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.storeEntity(CachedConnectionInterceptor.java:387) at org.jboss.ejb.EntityContainer.storeEntity(EntityContainer.java:714) at org.jboss.ejb.GlobalTxEntityMap.synchronizeEntities(GlobalTxEntityMap.java:149) at org.jboss.ejb.EntityContainer.synchronizeEntitiesWithinTransaction(EntityContainer.java:119) at org.jboss.ejb.plugins.cmp.jdbc.JDBCRemoveEntityCommand.execute(JDBCRemoveEntityCommand.java:95) at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.removeEntity(JDBCStoreManager.java:667) at org.jboss.ejb.plugins.CMPPersistenceManager.removeEntity(CMPPersistenceManager.java:492) at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.removeEntity(CachedConnectionInterceptor.java:430) at org.jboss.ejb.EntityContainer.remove(EntityContainer.java:505) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1084) at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:72) at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:282) at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185) at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:114) at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:163) at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:89) at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:54) at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84) at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:267) at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:128) at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118) at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191) at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122) at org.jboss.ejb.EntityContainer.internalInvoke(EntityContainer.java:489) at org.jboss.ejb.Container.invoke(Container.java:700) at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:375) at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38) at $Proxy99.remove(Unknown Source) at br.com.auge.bancoprojetos.dao.BancoProjetoEntityDAO.remove(BancoProjetoEntityDAO.java:48) at br.com.auge.bancoprojetos.appServices.BancoProjetosAppService.removeBancoProjeto(BancoProjetosAppService.java:191) at br.com.auge.bancoprojetos.facade.bean.BancoProjetosFacadeBean.removeBancoProjeto(BancoProjetosFacadeBean.java:98) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:683) at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185) at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72) at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84) at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:267) at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:128) at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118) at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191) at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122) at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331) at org.jboss.ejb.Container.invoke(Container.java:700) at sun.reflect.GeneratedMethodAccessor70.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284) at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546) at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:367) at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261) at sun.rmi.transport.Transport$1.run(Transport.java:148) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:144) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701) at java.lang.Thread.run(Thread.java:534)
I'm using CMP hence, no scaffolding code is written on the ejbRemove()
This null value, refers to the table projetoConfiguraDados, which have a id_banco_projeto attribute.
That's what I'm not understanding, why is jboss trying to update my table with a null value when
what I'm doing is trying to remove it.
Thanks for your help and time. -
4. Re: Problem with remove()
redbeard15 Oct 28, 2004 9:35 AM (in response to optimusprime)I'm only a newbie at writing CMP beans using JBoss, but I think JBoss implements
'cascade deletes' by first removing the 'parent' entity first (e.g., your entity A) and then
removes all related children (e.g., your entity B).
I suspect that if you had written the DB I/O code yourself, you would have reversed the
order of processing (like I would have). But it seems JBoss removes the parent entities
first in a cascade delete operation.
Consequently, it tries to maintain some level of consistency during this transaction by
setting the 'A' key in your 'B' table record to NULL for all related 'B' records. Then it
whacks the 'B' records.
Issues:
1) Is this really a problem? I struggled with this myself. It seems that the definition of a
transaction for a 'remove()' operation in JBoss CMP containers is quite large -- remove
the parent records first and then the child records. I've written quite a few tests to see if I
could break the system and I couldn't (good!).
2) You might be thinking in 'data model' mode vs. 'object model' mode. I also created my
data model first given the dozens of applications I wrote (before CMP beans) and then
tried to put CMP beans on top of it. I ran into all sorts of problems. In the end, I designed
my beans first and then created the tables below the beans (and did *not* use foreign
key constraints).
As long as I properly designed the beans so that the only way to add a child bean was to
create an 'addChild (B)' business method on my A bean. Seems to work pretty well. But
like I said, I'm still a newbie at this.....
R -
5. Re: Problem with remove()
raist_majere Oct 29, 2004 4:49 PM (in response to optimusprime)As redBeard15 says, I think the problem you have is that you setted the "on-delete-cascade" reference on the DB instead of on the CMR definition in ejb-jar.xml file. If that's your case, you should drop the "on-cascade-delete" rule on your DB and put the <on-cascade-delete\> element on the CMR definition.
If that's not your case, then I'll ask you to post your jbosscmp-jdbc.xml file, if you have it.
Tell us your results on this, please. -
6. Re: Problem with remove()
raist_majere Nov 3, 2004 8:47 PM (in response to optimusprime)Two days ago I read in the JBoss CMP docs about that, and now remembered about your problem. In that Docs it says that the FK column must be nullable in order for JBoss to work correctly. That's because, as said by redBear15, JBoss first deletes the parent entity and then makes the cascaded deletions.