Discussions

EJB programming & troubleshooting: can we modify the value of primary key in ejb2.0?

  1. can we modify the value of primary key in ejb2.0?
  2. no we can't modify the value of primary key
  3. You would never update the value of a primary key, since, you need the primary key to specify the row you are updating. To change its value makes for zero logical sense. :-)

    Raffi
  4. can we modify the value of primary key in ejb2.0?

    I would like to add one more question. how can I perform entity bean ejbRemove and ejbCreate method within one transaction?
    First, I called the remove method to delete one row, then called the create method immediately in order to create a row has the same keys as the row just has been deleted. But I encountered DuplicatedKeyException, should I have to use updating instead of deleting then inserting in a entity bean.
    Sorry about that my english is not good enough.
  5. I'm not sure of the proper terminology; I'm not a data modeler. But I was taught never to use a real field as a primary key; instead, generate a unique primary key. I think the reason for doing that applies to the situation you're dealing with. What is the business reason driving you to want to change the value of a primary key or delete a primary key and immediately create a new row with the same primary key value? If there is some business reason for changing the value of the field you're using as the primary key, yo should be able to do that without effecting the data model or any component model (EJB) based on the data model - and you could do that if you made the field you're using as primary key just another field and generated a primary key instead. A primary key who's only purpose is to simply provide a unique identifier for each row in the database table - nothing else. So no business rules every apply to it.