I think for CMP you need to need to create a primary key object in which you set your relevent attributes then pass that the ejbcreate. The persistant fields you regard as the primary key are not the same as what the container regards as the primary key - you therefor dont link the persistant fields to the primary key but let the container handle it.

This is a quote from SUN's J2EE TUTORIAL


Generating Primary Key Values

For some entity beans, the value of a primary key has a meaning for
the business entity. For example, in an entity bean that represents a
phone call to a support center, the primary key might include a time
stamp that indicates when the call was received. But for other beans,
the key's value is arbitrary--provided that it's unique. With
container-managed persistence, these key values can be generated
automatically by the EJB container. To take advantage of this feature,
an entity bean must meet these requirements:

In the deployment descriptor, the primary key class is defined as a
java.lang.Object. The primary key field is not specified.
In the home interface, the argument of the findByPrimaryKey method
must be a java.lang.Object.
In the entity bean class, the return type of the ejbCreate method must
be a java.lang.Object.

In these entity beans, the primary key values are in an internal field
that only the EJB container can access. You cannot associate the
primary key with a persistent field or any other instance variable.
However, you can fetch the bean's primary key by invoking the
getPrimaryKey method, and you can locate the bean by invoking its
findByPrimaryKey method.

--------------------
For more on this take a look at http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/CMP8.html#72960quoted  from J2EE Tutorial (by Sun) "Container-Managed Persistence
Examples" Chapter, Page 8

Hope that helps

Gareth

>From: Bernardus irmanto <[EMAIL PROTECTED]>
>Reply-To: Bernardus irmanto <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Error in creating Entity bean (CMP)
>Date: Fri, 7 Mar 2003 18:12:50 -0700
>
>hi,
>I have a CMP-entity bean which refers to a table with only 2 fields, and both are primary key. When I try to call create method, the container outputs the following error message :
>
>Can not call getPrimaryKey() inside ejbCreate(...) methods, the entity does not have an identity yet, see the EJB 2.0 specification chapter 10.5.4
>java.lang.IllegalStateException: Can not call getPrimaryKey() inside ejbCreate(...) methods, the entity does not have an identity yet, see the EJB 2.0 specification chapter 10.5.4
>
>inside the ejbCreate method, i put the following code :
>
>public PaketDetailBranchesPK ejbCreate(PaketDetailBranches objdata) throws CreateException {
> this.setStPacketCd(objdata.getStPacketCd());
> this.setStBranchId(objdata.getStBranchId());
> return null;
>}
>
>it seems to me that both fields must be inserted at the same time, (I know that it can be done easily using BMP)
>
>can anyone give me hint ?
>
>
>tha
>
>beN
>
>===========================================================================
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff EJB-INTEREST". For general help, send email to
>[EMAIL PROTECTED] and include in the body of the message "help".


Chat with friends online - download MSN Messenger today. =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff EJB-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to