7 Replies Latest reply on Sep 19, 2002 2:38 PM by dsundstrom

    i cant set relations - can somebody help?

    brecicure

      i am using JBoss 3.0.2. I want to know WHEN is the proper time to use the SETxxxx method to relate an entity bean to other entity beans.

      I have, for example, a CMP entity bean, Purchase, that relates to other 2 CMP entity beans, Employee and Company. AFTER executing ejbCreate(), i understand that ejbPostCreate() should be invoked.

      In ejbPostCreate() i did:

      purchase.setEmployee(here goes a LocalEmployee employee)
      purchase.setCompany(here goes a LocalCompany company)

      after running a test case, i go and check in the database. Result: the Purchase record has been created (ejbCreate has been properly executed), but the record has NOT been related to the other entity beans.

      Please help me on this one, i have been able to solve many other problems, but i have been working on this for 3 days now...no ideas yet. thanks in advance.

        • 1. Re: i cant set relations - can somebody help?
          sweetfa

          ejbPostCreate is being called OK.

          Do you have the correct multiplicity in your relationship definition.

          If you have am multiplicity of 1-1 you may find problems with it only setting one, and the rest remaining blank...

          • 2. Re: i cant set relations - can somebody help?
            catriona

            Hi

            I am having this problem also. I have two CMP2.x Entity beans with a many to many relationship. When I create a relation by calling the setXXX on one of my entity beans after creation, it does not put any data into the relation table. It does not throw any errors and I have no idea why this is happeneing.

            I would be very grateful if anybody has had this problem before and has any advice.

            Thanks
            C

            • 3. Re: i cant set relations - can somebody help?
              brendelk

              I think my problem is related to this. I have foreign keys and constarints for them. When ejbCreate is called I have an exception in JBoss:

              INFO [jbossweb] ActionServlet: Create error: javax.ejb.CreateException:
              Could not create entity:java.sql.SQLException: Try to insert null into a
              non-nullable column in statement [INSERT INTO RESERVATIONS (reservation_id,
              person_id_fk, flight_id_fk, registration_utc, comment, person_id_fk,
              flight_id_fk) VALUES (5, 5, 5, '2002-11-11 11:11:11.0', 'jgkgjgh',
              NULL, NULL)]

              Draw attention that person_id_fk, flight_id_fk repeated two times. Last time it is overwriten by null values. And due to fields are not null exception is thrown.

              • 4. Re: i cant set relations - can somebody help?
                fsaint

                I found the same problem in jboss-3.0.0+tomcat, using jboss-3.0.3RC1 fixed the problem.

                • 5. Re: i cant set relations - can somebody help?
                  dsundstrom

                  Yep, I fixed this a couple of weeks ago.

                  • 6. Re: i cant set relations - can somebody help?
                    cosmic_crusader

                    > ejbPostCreate is being called OK.
                    >
                    > Do you have the correct multiplicity in your
                    > relationship definition.
                    >
                    > If you have am multiplicity of 1-1 you may find
                    > problems with it only setting one, and the rest
                    > remaining blank...

                    I too am experiencing this problem of a 1-1 relationship not being set on the ejbPostCreate().

                    The method gets called without incident, but the database does not reflect it?

                    However if I call the setter method after the creation (on the Local interface) then it works fine. However I woudl prefer not to expose the setter method and have it set in creation only.

                    (Oh and just to cover all the bases I tried calling the setter method in the ejbPostCreate when the setter method was on the local interface but it made no difference).

                    Is this a bug or valid behaviour?

                    • 7. Re: i cant set relations - can somebody help?
                      dsundstrom

                      This is an old bug. Are you using JBoss 3.0.2 or newer?