how to create an entity bean without primary key

Discussions

EJB programming & troubleshooting: how to create an entity bean without primary key

  1. hi,

    I'm using EJB and i have a question about Entity Bean component. I read that
    we can create entity bean without primary key, but one does not explain what
    it is necessary to put in the descrpitor ejb-jar.xml, if we must remove or
    keep tags referenced a primary key (such <prim-key-class>....)?

    Thank you

    Salim
  2. I read that we can create entity bean without primary key

    I'd very much like to read that... entity EJB with no primary key makes no sense to me. That's why we have session EJBs...

    Regards,
    Martin
  3. you are right, an entity bean without primary key has not sense for me also. Indeed, I didn’t say all, but what I would like exactly is to merge two EJBs source by creating a new Entity bean and establishing two relationships from this new EJB to them. On other hand, to avoid the redundant stocked data in Database, I want to consider that the primary key of the new Entity bean is a one of the two established relationship.

    Thanks by advance if you can help me.

    Salim
  4. You mean you want to avoid GENERATING the primary key? What's re relationship model? Cardinality, navegability and so on? What component is responsible for creating instances of this new EJB?
    I might be able to help with this info.

    Regards,
    Martin
  5. It is exactly what I wanted. both relationships between the new EJB and the two ejbs source to be merged are one to one with an unidirectionel navigability towards the EJBs source

    thank you
  6. Who's responsible for creating instances of this new EJB? I guess the relationships between the new EJB and the two original ones represent aggregations: "EJB A and EJB B aggregate the new EJB".
    If that's the case, no matter who creates instances of the new EJB; it's ejbCreate() method should receive the related instances of the other EJBs and generate its own PK from them. Minor sample:

    public class NewEjb implements EntityBean
    {
       //...

       public NewEjbPKey ejbCreate(EjbA a, EjbB b)
          throws CreateException
       {
          setPKey(new NewEjbPKey(a.getPKey(), b.getPKey()));
          // store in DB.
          return getPKey();
       }
       //...
    }

    Hope this represents your semantics...

    Regards,
    Martin
  7. On the contrary, it is the new EJB which aggragate the both orignal ones.
    It doesn't matter, I think that your propositon answers well my requète. made a thing resembling your proposal, but by using the ejbStore method, but I think that it is more judicious to make it at the creation of EJB like your proposal. I will try it and will keep you informed.
     
    below the scheme of the aggregation

             /-> EJBa
    New EJB
             \-> EJBb

    Thanks a lot
    regards,
     Salim
  8. excuse me, I was mistaken, I used ejbPostCreat method and not ejbStrore method as mentioned in my message

    regards,
    Salim