5 Replies Latest reply on Sep 10, 2001 11:30 PM by haytona

    Persistent arrays of entity beans in an entity bean

    lk

      I would like to have one entity bean reference a few other entity beans. I implemented this as a public field being an array of entity bean remote interfaces and made this field a cmp-field in ejb-jar.xml file. Unfortunately, JBoss throws exceptions at me:

      [Tel] TRANSACTION ROLLBACK EXCEPTION:Load failed; nested exception is:
      No class found for oid.; nested exception is:
      java.rmi.ServerException: Load failed; nested exception is:
      No class found for oid.
      [Tel] java.rmi.ServerException: Load failed; nested exception is:
      [Tel] No class found for oid.
      [Tel] No class found for oid.
      [Tel] at org.postgresql.Connection.getObject(Connection.java:770)
      [Tel] at org.postgresql.jdbc2.Connection.getObject(Connection.java:525)
      [...]

      Is there any other way to implement one-to-many relation with CMP entity beans?

        • 1. Re: Persistent arrays of entity beans in an entity bean

          You can refer in the detail beans to the master bean using a foreign key, that is add a field to the one bean (the foreign key) which refers to the many bean.

          • 2. Re: Persistent arrays of entity beans in an entity bean
            lk

            What exactly is "many bean"? So far I have to implement a BPM-type bean and create additional table in the database holding information about one-to-many references among my beans (the many-sided bean may be CMP-type).

            • 3. Re: Persistent arrays of entity beans in an entity bean

              Check out EJB 2.0 persistance.
              (For jBoss, at the moment, only available with a add on from mvcsoft.com)

              • 4. Re: Persistent arrays of entity beans in an entity bean
                ghilling

                You cannot save an array of beans because this is neither a simple Java type nor a serializable
                Object.
                Get yourself Handles to the Objects and put them into a Container. This is a serializable Object so this Method works (at least for me). You will just have to re-get the Objects from the Handles ...

                (If this works for me only by chance please mail me a note...)

                -Gunnar

                • 5. Re: Persistent arrays of entity beans in an entity bean
                  haytona

                  Storing an array of primary key objects for the related beans rather than handles should give better flexibility and performance at the expense of "good" OO principals (IMHO).
                  I made a simple example using an Order EJB which has many OrderLine EJBs. Each OrderLine has only one Order. Classic 1-N relationship. I stored the Order PrimaryKey (in my case a string) in the OrderLine and when i wanted to get the order lines for an order I called order.getOrderLines() which returned a collection of OrderLine references. This method called findByOrderId(order.getId()) from the OrderLineHome interface. Seemed to work ok for me. It is possible to do n-n relationships like this too.
                  For more info see www.geocities.com/haytona/reltut/ for more info and code examples.

                  hope this helps
                  hamish