Creating EntityBean without a Key

Discussions

EJB design: Creating EntityBean without a Key

  1. Creating EntityBean without a Key (2 messages)

    We are having a problem with EntityBeans and I think it is a generalized problem and wondered how others are solving it.
    With EntityBeans, you can invoke a Finder method to find a particular entity (or collection of them). You can also invoke a create method to create a new entity with the specified Key. However, How do you create a new EntityBean when you supply a set of data and the persistent store creates the key for you?
    Our situation: We are wrapping a host system function to create a BusinessEntity. The host system takes a small set of data and creates the Entity, including the key identifying the Entity. We have not found a way to do this using EntityBeans. We can do this create via a SessionBean, but whenever we try to put it on the EntityBean, we run into problems with the ejbLoad being invoke (which doesn't make sense because we are not loading it).

    Any thoughts/comments would be helpful.

    Thanks,
    Mike
  2. Two possibilities come to mind:

    - You could use BMP, in which case the primary key value is returned from ejbCreate and need not be known before the database was accessed.

    - You could use a stateless session bean to get a transaction context in which to call your persistant store's create routine, then, in the same transaction context do a normal findByPrimaryKey to locate the entity bean.
  3. Two possibilities come to mind:

    - You could use BMP, in which case the primary key value is returned from ejbCreate and need not be known before the database was accessed.

    - You could use a stateless session bean to get a transaction context in which to call your persistant store's create routine, then, in the same transaction context do a normal findByPrimaryKey to locate the entity bean.