14 Replies Latest reply on Jul 18, 2003 9:25 AM by Juha Lindfors

    1-to-many relationship does not work - jBoss 3.2.1

    steffenboehme Newbie

      Hi there,

      i have i problem with an 1-to-many relationship between 2 cmp-beans and i can't solve this.

      i think the xDoclet-Tags are not correct, but i have don't know, whats wrong ... maybe i'm thinking wrong :-(

      my code is the following:

      1. Bean:

      /**
      * @author sbo
      *
      * @ejb.bean
      * name = "Parent"
      * type = "CMP"
      * primkey-field="id"
      * jndi-name = "de/boemm/ejb/parent"
      * cmp-version = "2.x"
      * view-type = "remote"
      * schema = "parentSchema"
      *
      * @ejb.home local-class = "de/boemm/interfaces/ParentHome"
      *
      * @ejb.persistence
      * table-name="parent"
      *
      * @jboss.persistence
      * datasource = "java:/OracleDS"
      * datasource-mapping = "Oracle9i"
      *
      * @ejb.finder
      * query="SELECT OBJECT(a) FROM parentSchema as a"
      * signature="java.util.Collection findAll()"
      */
      ...
      // The primary key & the field for the relation (the 1-site)
      /**
      * @ejb.persistence
      * column-name = "ID"
      * sql-type = "NUMBER"
      *
      * @ejb.interface-method
      *
      * @ejb.relation
      * name = "ParentChildRelation"
      * role-name = "Parent_of_Childs"
      */
      public abstract java.lang.Long getId();


      2. Bean:

      /**
      * @author sbo
      *
      * @ejb.bean
      * name = "Child"
      * type = "CMP"
      * primkey-field="id"
      * jndi-name = "de/boemm/ejb/child"
      * cmp-version = "2.x"
      * view-type = "remote"
      * schema = "childSchema"
      *
      * @ejb.home local-class = "de/boemm/interfaces/ChildHome"
      *
      * @ejb.persistence
      * table-name="child"
      *
      * @jboss.persistence
      * datasource = "java:/OracleDS"
      * datasource-mapping = "Oracle9i"
      *
      * @ejb.finder
      * query="SELECT OBJECT(a) FROM childSchema as a"
      * signature="java.util.Collection findAll()"
      */
      ...
      // The primary Key
      /**
      * @ejb.persistence
      * column-name = "ID"
      * sql-type = "NUMBER"
      * @ejb.interface-method
      */
      public abstract java.lang.Long getId();
      ...
      // The field for the relation (the many-site)
      /**
      * @ejb.persistence
      * column-name = "PARENT_ID"
      * sql-type = "NUMBER"
      *
      * @ejb.interface-method
      *
      * @ejb.relation
      * name = "ParentChildRelation"
      * role-name = "Child_of_Parent"
      *
      * @jboss.relation
      * related-pk-field = "parentId"
      * fk-column = "PARENT_ID"
      */
      public abstract java.lang.Long getParentId();


      Now there are some questions:
      1. is in the 1. Bean also a "@jboss.relation"-tag required?
      2. can the fk-field in the 2. Bean be a non-primary-key-field?
      3. must the "related-pk-field" in the "@jboss.relation"-tag in the 2. Bean point to the pk-field in the 1. Bean?

      if i compile this code and deploy the bean i get the following exception:

      org.jboss.deployment.DeploymentException: CMP field for key not found: field name=parentId

      i don't know, how the code must be changed, that this simple example is right ... i hope someone can write me a little suggestion and shows me, where the mistakes are.
      i use xDoclet 1.1.2 and the jBoss 3.2.1-version.

      Thank you very much
      Steffen

        • 1. Re: 1-to-many relationship does not work - jBoss 3.2.1
          Juha Lindfors Master

          It's easier to work with the XML deployment descriptors first rather than trying to wade through the xdoclet crapola. Once you understand what the deployment descriptors *should* look like should you start using Xdoclet.

          Please attach the deployment descriptors that xdoclet generates. It is usually easier trying to figure out the problem from those.

          • 2. Re: 1-to-many relationship does not work - jBoss 3.2.1
            sreram Newbie

            I tried with XML deployment descriptors also. I have gone through jboss related document. I have cross validated with jbosscmp-jdbc.xml descriptor also. everything seems to be fine. when I try to run the stub for the entity beans it is giving the error as follows

            "duplicate column name".

            Also, is there a way to find out the queries generated for CMP/CMR Entity bean.

            • 3. Re: 1-to-many relationship does not work - jBoss 3.2.1
              Juha Lindfors Master

              Set the logging to debug level for the CMP engine. How to do this is explained in the documentation.

              • 4. Re: 1-to-many relationship does not work - jBoss 3.2.1
                sreram Newbie

                thanks a lot for the tip to change the logging level to DEBUG. now I am clear about the problem.

                In the sql-query that jboss is creating is displayed on the console. it is adding an extra column with the same name. what is the reason for such a behaviour.

                • 5. Re: 1-to-many relationship does not work - jBoss 3.2.1
                  Juha Lindfors Master

                  attach your deployment descriptors, the reason is most likely a configuration error

                  • 6. Re: 1-to-many relationship does not work - jBoss 3.2.1
                    steffenboehme Newbie

                    May it be, that you are using a jBoss version < 3.2.* ?
                    Then the Problem is, that this versions can't use a existing cmp-field as a foreign-key-field at the same time.
                    I had the same problem and with the newer version (3.2.1) does the problem not occur.
                    so you must either set a new field as only cmr but not a cmp-field, or you upgrade to the newer jboss-versions ...

                    i hope, this is not wrong ... am just a beginner in the ejb- and jBoss-universum but this was my first :-) mistake and this one i had fixed ...

                    Steffen

                    • 7. Re: 1-to-many relationship does not work - jBoss 3.2.1
                      sreram Newbie

                      I had 3.0.3 version installed. I have upgraded it to 3.2.1 version.

                      now the queries that are getting created is fine. but is giving null pointer exception. the following is the exception that is occuring

                      20:55:02,688 DEBUG [ProcessPersistanceBean] Create: pk=2
                      20:55:02,938 DEBUG [ProcessPersistanceBean] Executing SQL: SELECT COUNT(*) FROM FB_PROCESS_INSTANCE_TB WHERE INSTANCE_ID=?
                      20:55:02,938 DEBUG [ProcessPersistanceBean] [ProcessPersistanceBean.ejbCreate] Executing SQL: INSERT INTO FB_PROCESS_INSTANCE_TB (INSTANCE_ID, INSTANC
                      E_STATE, PRIORITY, PARENT_PROCESS_INSTANCE_ID, START_TIME, FLOW_TYPE, END_TIME, LAST_MODIFIED_TIME, DEFINITION_ID, INSTANCE_NAME, OWNER) VALUES (?, ?,
                      ?, ?, ?, ?, ?, ?, ?, ?, ?)
                      20:55:02,954 DEBUG [ProcessPersistanceBean] Rows affected = 1
                      20:55:03,032 DEBUG [ProcessAttributeBean] Create: pk=AIdtow
                      20:55:03,032 DEBUG [ProcessAttributeBean] Executing SQL: SELECT COUNT(*) FROM FB_PROCESS_ATTRIBUTES_TB WHERE ATTRIBUTE_ID=?
                      20:55:03,048 DEBUG [ProcessAttributeBean] [ProcessAttributeBean.ejbCreate] Executing SQL: INSERT INTO FB_PROCESS_ATTRIBUTES_TB (ATTRIBUTE_ID, ATTRIBUT
                      E_TYPE, ATTRIBUTE_LENGTH, ATTRIBUTE_VALUE, ATTRIBUTE_ELEMENT_TYPE, PROCESS_INSTANCE_ID, ATTRIBUTE_NAME) VALUES (?, ?, ?, ?, ?, ?, ?)
                      20:55:03,063 DEBUG [ProcessAttributeBean] Rows affected = 1
                      20:55:03,126 ERROR [LogInterceptor] EJBException, causedBy:
                      java.lang.NullPointerException
                      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.add(RelationSet.java:101)
                      at com.wipro.flowbrix.workflow.wapi.eb_persistance.ProcessPersistanceBean.setAttributeList(ProcessPersistanceBean.java:403)
                      at com.wipro.flowbrix.workflow.wapi.eb_persistance.ProcessPersistanceBean.ejbPostCreate(ProcessPersistanceBean.java:270)
                      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.plugins.CMPPersistenceManager.postCreateEntity(CMPPersistenceManager.java:260)
                      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.postCreateEntity(CachedConnectionInterceptor.java:278)
                      at org.jboss.ejb.EntityContainer.postCreateHome(EntityContainer.java:713)
                      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:1032)
                      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:95)
                      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:301)
                      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
                      at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:82)
                      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:174)
                      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:89)
                      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:43)
                      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
                      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
                      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:74)
                      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:92)
                      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120)
                      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
                      at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:477)
                      at org.jboss.ejb.Container.invoke(Container.java:694)
                      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.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
                      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
                      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:101)
                      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:83)
                      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:46)
                      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
                      at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:173)
                      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
                      at $Proxy34.create(Unknown Source)
                      at org.apache.jsp.PersistanceCRTest_jsp._jspService(PersistanceCRTest_jsp.java:128)
                      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
                      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
                      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
                      at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
                      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)
                      at org.mortbay.http.HttpContext.handle(HttpContext.java:1714)
                      at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:507)
                      at org.mortbay.http.HttpContext.handle(HttpContext.java:1664)
                      at org.mortbay.http.HttpServer.service(HttpServer.java:863)
                      at org.jboss.jetty.Jetty.service(Jetty.java:460)
                      at org.mortbay.http.HttpConnection.service(HttpConnection.java:775)
                      at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:939)
                      at org.mortbay.http.HttpConnection.handle(HttpConnection.java:792)
                      at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)
                      at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
                      at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)
                      20:55:03,126 WARN [jbossweb] WARNING: Exception for /release2.0.2/flowbrix/test/PersistanceCRTest.jsp: java.rmi.ServerException: EJBException:; neste
                      d exception is:
                      javax.ejb.EJBException: null; CausedByException is:
                      null


                      can anybody dissect this for me.

                      • 8. Re: 1-to-many relationship does not work - jBoss 3.2.1
                        steffenboehme Newbie

                        Oh, i'm sorry but i can't help you in this case ...

                        i'm just a beginner ;-)

                        one question about the debug-funktionality
                        can you tell me, how i can enable the debug-output in the console?

                        i had searched for this in the jboss beginners tutorial but a had nothing found about this, just about output to the logfile

                        the detailed messages in your postings (for instance the sql-querys) would be a great help for the development ...

                        tnx
                        Steffen

                        • 9. Re: 1-to-many relationship does not work - jBoss 3.2.1
                          pauster007 Newbie

                          > Oh, i'm sorry but i can't help you in this case ...
                          >
                          > i'm just a beginner ;-)
                          >
                          > one question about the debug-funktionality
                          > can you tell me, how i can enable the debug-output in
                          > the console?
                          >
                          > i had searched for this in the jboss beginners
                          > tutorial but a had nothing found about this, just
                          > about output to the logfile
                          >
                          > the detailed messages in your postings (for instance
                          > the sql-querys) would be a great help for the
                          > development ...
                          >
                          > tnx
                          > Steffen



                          yeah can you please tell us how to enable the debug feature?

                          • 10. Re: 1-to-many relationship does not work - jBoss 3.2.1
                            pittala Newbie

                            In conf/log4jxx.xml insert lines




                            This should be in the limit categories section...
                            hope this helps...

                            • 11. Re: 1-to-many relationship does not work - jBoss 3.2.1
                              steffenboehme Newbie

                              Hi,

                              i had already tryed this, but unfortunately this does not have the needed effect.
                              is it possible, that this does not work because the entries are to "limit" the output and not to increase it!?

                              so i think (and tryed also) that this is no way to increase the output ... but thank you anyway.

                              Steffen

                              • 12. Re: 1-to-many relationship does not work - jBoss 3.2.1
                                Juha Lindfors Master

                                make sure your console appender threshold is set to debug

                                -- Juha

                                • 13. Re: 1-to-many relationship does not work - jBoss 3.2.1
                                  steffenboehme Newbie

                                  Yes, thats possible, but if i start jboss with this option () than i

                                  1. don't need to insert the above categorie-tag (all output is debug!)
                                  2. the startup needs up to 7 minutes! because of the very much messages :-)

                                  so the question is: can i tell the jboss that the log-level is info except the "org.jboss.ejb.plugins.cmp"-classes, they are in debug-level ... thats not working with the tag:




                                  grmpff

                                  Steffen ;-)

                                  • 14. Re: 1-to-many relationship does not work - jBoss 3.2.1
                                    Juha Lindfors Master

                                    limit jboss categories to INFO

                                    -- Juha