Discussions

EJB design: Primary key in Entity beans

  1. Primary key in Entity beans (3 messages)

    Hi

    If my database doesn’t have primary key, then how can I define ejbFindByPrimarykey method. ? or in that case can’t I use Entity beans. ?
    Pls clear my doubt.

    Thanks in advance.
  2. Primary key in Entity beans[ Go to top ]

    You should ask yourself a different question:
    "How am I going to get data out of my database"?

    There is no requirement for an EJB to use a DB defined primary key for extracting data. Because a database doesn't have a primary key defined does not mean that the data is not keyed. It must be, for if it was not, you couldn't ask the database to retrieve a unique row for you.

    So what you do in your case, is forget that the DB doesn't have a defined primary key and define your own EJB primary key based upon knowledge of the data you're trying to access.

    Does this make any sense, and does it help?

    Dave
  3. Primary key in Entity beans[ Go to top ]

    I've had a longer think about this, and I can conceive of a case where a DB table wouldn't have a unique key per row. An example of this might be where the rows in a table are keyed to another table via say a transaction ID. Multiple entries could share the same foreign key. In this case there need never be a requirement to retrieve a single row.

    What this would mean in the EJB world is that you couldn't have an Entity Bean representing these entities. If you think about it though, you wouldn't want to. It'd be the transaction level data that would be the Entity with the lower level stuff forming part of that Entity.

    I don't think Ive explained this very well. Hope you understand what I'm trying to say.

    Dave

  4. Primary key in Entity beans[ Go to top ]

    My problem seems to be similar : I try to map a CMP on a VIEW.

    What about EJB specifications ? Is it allowed to use Entity bean mapped on table without primary key (or view) and only use our own custom find ?

    In my case, I would like to map a CMP on a VIEW. The problem is Visual Age don't let me define TABLE without primary key ... define VIEW under VAJ seems not exist.

    Another crucial question :
    can view have primary keys ?

    Thanks.

    Damien