Help with a strange relation between entities - Weblogic

This is a discussion on Help with a strange relation between entities - Weblogic ; Hi, I need to have a relation between two entities A and B, A has many B's and B has one A. Also, A need to say that one B is its Leader ( or something like that). The problem ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Help with a strange relation between entities

  1. Help with a strange relation between entities


    Hi, I need to have a relation between two entities A and B, A has many B's and
    B has one A. Also, A need to say that one B is its Leader ( or something like
    that). The problem is that when I create one object of type A I as well create
    one object of type B, the creations never was sucessfull because the container
    says me that "...PARENT KEY NOT FOUND"...of course one o those relations are nullable
    in the database....I need help about this problem, how I must to manage the transaction?.
    My two entities are CMP's.

    Thanks in advance,

    Here is the code...Of course this is an example, it is not my real code, but it
    is in others words the same that I am making...

    ALocal a = createA(AVO);

    BLocal b = createB(bVO,a); //Until here, It works!!!

    //I try to save the relation of A toward B
    a.setLeader(b); //Parent key not found ERROR!

    I am working in weblogic 8.1...


  2. Re: Help with a strange relation between entities


    Hi,

    I'm not sure I follow. Do you instead mean that the relationship is NOT nullable
    (rather than nullable). Is there a foreign key constraint defined between the
    DBMS tables ?
    What is the exact message including message number returned ?

    What may be happening is that the relationship needs to be set in an
    ejbPostCreate method as mentioned in:

    http://newsgroups.bea.com/cgi-bin/dn...item=740&utag=


    -thorick





  3. Re: Help with a strange relation between entities


    Upps, you are right, I mean that the column in the database are nullable. Let me
    give you the structures of my tables:

    Table Group(
    cd_group NUMBER NOT NULL PK,
    nb_group VARCHAR2 NOT NULL,
    cd_leader NUMBER FK to cd_member in Member
    )

    Table Member(
    cd_member NUMBER NOT NULL PK,
    nb_member VARCHAR2 NOT NULL ,
    cd_group NUMBER NOT NULL FK to cd_group in Group
    )

    and the code...in an java control. The relation of member to group is the one
    that is mandatory, and is the one that I set in the postcreate method of this
    entity.

    ...
    1 GroupLocal groupLocal = insertGroup(groupVO);

    2 MemberLocal memberLocal= insertMember(memberVO,groupLocal);

    //Make the relation, away of the create method
    3 groupLocal.setLeader(memberLocal);

    The error is in line 3:

    sql.SQLException: ORA-02291:integrity constraint (G1FEI3.FK_CM_SUJETO_CM_PUNTO)
    violated - parent key not found...

    I think that before line 3, the member entity has not been created and when I
    try to set it in the "Leader" relation it does not find the constraint in the
    database. The two entities have the "delay-database-insert-until=ejbPostCreate".

    Well I make it works put in the entity Member the tag "default-transaction = RequiresNew"
    but it only work in this case. I would like to know if you have one idea on how
    to manage the transaction in this case.

    Thanks in advance, please excuse my english...

    att,

    monica a.


  4. Re: Help with a strange relation between entities


    Hi,

    I don't quite follow which code is in the postCreateMethod of which bean,
    but since the Member bean is the one that has the NOT NULL constraint
    then I'd guess that the Member beans ejbPostCreate method needs to
    contain something like:

    member.ejbPostCreate( , group ) {
    < set all member_fields >
    setGroupRelationship(group); // I don't know the name of this cmr-field
    }

    If everything is set up right, then this would set the
    foreign key column cd_group in the member bean
    before the database write takes place and the
    foreign key NOT NULL constraint will be satisfied.

    -thorick

  5. Re: Help with a strange relation between entities


    My opinion,

    1 GroupLocal groupLocal = insertGroup(groupVO);

    2 MemberLocal memberLocal= insertMember(memberVO,groupLocal);

    DO NOT TRY TO SET THE VALUE OF cd_group IN THE ejbCreate method of Member Entity
    Bean. Try to set the value of CMR field of cd_group to the value you recieve from
    grouplocal in ejbPostCreate method of Member Entity Bean. This is mandatory if
    the cd_group field is NOT NULL.

    "monica" wrote:
    >
    >Upps, you are right, I mean that the column in the database are nullable.
    >Let me
    >give you the structures of my tables:
    >
    >Table Group(
    > cd_group NUMBER NOT NULL PK,
    > nb_group VARCHAR2 NOT NULL,
    > cd_leader NUMBER FK to cd_member in Member
    >)
    >
    >Table Member(
    > cd_member NUMBER NOT NULL PK,
    > nb_member VARCHAR2 NOT NULL ,
    > cd_group NUMBER NOT NULL FK to cd_group in Group
    >)
    >
    >and the code...in an java control. The relation of member to group is
    >the one
    >that is mandatory, and is the one that I set in the postcreate method
    >of this
    >entity.
    >
    >...
    >1 GroupLocal groupLocal = insertGroup(groupVO);
    >
    >2 MemberLocal memberLocal= insertMember(memberVO,groupLocal);
    >
    > //Make the relation, away of the create method
    >3 groupLocal.setLeader(memberLocal);
    >
    >The error is in line 3:
    >
    >sql.SQLException: ORA-02291:integrity constraint (G1FEI3.FK_CM_SUJETO_CM_PUNTO)
    >violated - parent key not found...
    >
    >I think that before line 3, the member entity has not been created and
    >when I
    >try to set it in the "Leader" relation it does not find the constraint
    >in the
    >database. The two entities have the "delay-database-insert-until=ejbPostCreate".
    >
    >Well I make it works put in the entity Member the tag "default-transaction
    >= RequiresNew"
    >but it only work in this case. I would like to know if you have one
    >idea on how
    >to manage the transaction in this case.
    >
    >Thanks in advance, please excuse my english...
    >
    >att,
    >
    >monica a.
    >



  6. Re: Help with a strange relation between entities


    If you are still having the problem after what sonal suggested make sure you set
    the flag order-database-operations to false and set the cmr fields in post create
    (as suggested). This flag has to be set to false for delay flag to be effective.

    S

    "monica" wrote:
    >
    >Hi, I need to have a relation between two entities A and B, A has many
    >B's and
    >B has one A. Also, A need to say that one B is its Leader ( or something
    >like
    >that). The problem is that when I create one object of type A I as well
    >create
    >one object of type B, the creations never was sucessfull because the
    >container
    >says me that "...PARENT KEY NOT FOUND"...of course one o those relations
    >are nullable
    >in the database....I need help about this problem, how I must to manage
    >the transaction?.
    >My two entities are CMP's.
    >
    >Thanks in advance,
    >
    >Here is the code...Of course this is an example, it is not my real code,
    >but it
    >is in others words the same that I am making...
    >
    > ALocal a = createA(AVO);
    >
    > BLocal b = createB(bVO,a); //Until here, It works!!!
    >
    > //I try to save the relation of A toward B
    > a.setLeader(b); //Parent key not found ERROR!
    >
    >I am working in weblogic 8.1...
    >



+ Reply to Thread