13 Replies Latest reply on Apr 9, 2002 9:54 AM by Georg Schmid

    CMR woes

    Philip W Craven Newbie

      When I create two beans that can be related, and then relate them, I have no problem. When I create these beans, and then try and relate them I get the error at the end of this post. I am using the current tip. I am not using a jbosscmp-jdbc.xml file, but I was under the impression that this file is not required. Any help would be greatly appreciated.

      13:40:48,408 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
      java.lang.IllegalStateException: A CMR field cannot be set or added to a relationship in ejbCreate; this should be done in the ejbPostCreate method instead.
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.addRelation(JDBCCMRFieldBridge.java:696)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.createRelationLinks(JDBCCMRFieldBridge.java:549)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.add(RelationSet.java:87)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.addAll(RelationSet.java:106)
      at com.blackbearsolutions.fea.biz.QuestionSet_Bean.addQuestionSetDependency(QuestionSet_Bean.java:35) at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1012)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCReadAheadInterceptor.invoke(JDBCReadAheadInterceptor.java:92)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:184)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:295)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:189)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:108)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:158)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:64)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:435)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLocalContainerInvoker.java:346)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker$EntityProxy.invoke(BaseLocalContainerInvoker.java:475)
      at $Proxy21.addQuestionSetDependency(Unknown Source)
      at com.blackbearsolutions.fea.biz.TestHarnessBean.doSomething(TestHarnessBean.java:42)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:623)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:77)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:158)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:64)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:127)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:289)
      at org.jboss.ejb.Container.invoke(Container.java:609)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1555)
      at com.sun.management.jmx.MBeanServerImpl.invoke(MBeanServerImpl.java:1523)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:320)
      at java.lang.reflect.Method.invoke(Native Method)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
      at sun.rmi.transport.Transport$1.run(Transport.java:152)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:148)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:465)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:706)
      at java.lang.Thread.run(Thread.java:484)

        • 1. Re: CMR woes
          Mac Rinehart Newbie

          My psychic powers tell me you're attempting to set the CMR field in the ejbCreate method. I suggest postponing the invocation of the CMR setter until the ejbPostCreate method. :)

          - Mac

          • 2. Re: CMR woes
            Philip W Craven Newbie

            No I am not trying to set the CMR field in the create method. Also the most annoying thing here is that if I set the CMR field when I initially create the two objects (same transaction I would imagine), then everything is groovy. It is only the second time around that there are issues.

            • 3. Re: CMR woes
              Mac Rinehart Newbie

              Well, I guess my membership in the psychic friends network is revoked. :(

              The error message is misleading. If the entities are already created, then that message shouldn't be displayed. I did some snooping around, and it seems that in JDBCEntityBridge.getEntityState, if the EntityState retrieved by the EntityEnterpriseContext is null, then a new entity state is created. If that is happening, then I wonder if the container is actually duped into thinking that you entity bean hasn't been created when it's already present...

              Did the entities get inserted into the database properly when you created them? And this is just a random thought, but I had some problems yesterday with persistence management that were caused by problems with my primary key equals and hashCode methods. Might be something to check out.

              Hope that helps :)

              • 4. Re: CMR woes
                Philip W Craven Newbie

                The database insert was successful, and I can access all of the attributes of each object when I retrieve it. The problem only occurs when I try to do the CMR hook up. One question, I am not using the jbosscmp-jdbc.xml file, but I am under the impression that this is optional. Is that a valid assumption?

                • 5. Re: CMR woes
                  Mac Rinehart Newbie

                  Regarding jbosscmp-jdbc.xml, that is my understanding. FYI, although I had primary key problem I was also able to insert into the database, and the fields were correctly populated. The clue was when I attempted to update the database performed a delete and another insert with the change, rather than doing an update.

                  - Mac

                  • 6. Re: CMR woes
                    Dain Sundstrom Master

                    I think I fixed this problem is cvs last week. If you want, try the current cvs code.

                    • 7. Re: CMR woes
                      Philip W Craven Newbie

                      I was using the tip from Sunday, and there is still no joy from it. What do you need from me to make sure that the problem is not me being foolish?

                      • 8. Re: CMR woes
                        Dain Sundstrom Master

                        Ok, what exactly are you doing? Do you create the beans in one transaction, say parent and child, and then call child.setParent(parent) in another transaction?

                        It would be very helpful for you to post a bug report at sourceforge. It would be even better if you could include a test that demonstrates the behavior.

                        • 9. Re: CMR woes
                          Philip W Craven Newbie

                          here is both a tar of my working directory as well as the deployable jar. If there is anything else please let me know. If there was a better way to get help please let me know.
                          Thanks

                          • 10. Re: CMR woes
                            Dain Sundstrom Master

                            Post a bug report at source forge.

                            • 11. Re: CMR woes
                              Philip W Craven Newbie

                              In the future or for this item as well? Also if I am posting a bug report on sourceforge for this item, should I attach the items that I have attached here as well?

                              • 12. Re: CMR woes
                                Dain Sundstrom Master

                                The bug report should be a complete stand alone item.

                                • 13. Re: CMR woes
                                  Georg Schmid Newbie


                                  I am running into this problem (just as it is
                                  described in the thread: second time around
                                  the IllegalStateException kicks in).

                                  My code is something like:

                                  Collection details = new ArrayList();
                                  ... add DetailLocal items to details list...

                                  MasterLocal master = readMaster( masterId );
                                  master.setDetails( details );

                                  Has this been fixed in the current RH CVS head?

                                  Thanks in advance.

                                  Georg