In EJB 2.0(CMP) can the return type needs to be String, Integer etc or can this be an object class like custPK(assumming we have this defined as below). To me seems this will be illegal as return type needs to be declared in DD. The reason for this question is that I have some old code (EJB 1.1)that runs into problem when running in OC4J new version(EJB 2.0) that is suppoSed to be backwarD compAtible and I am thinking it is not.
Originally posted by Raj Puri: In EJB 2.0(CMP) can the return type ... be an object class like custPK(assumming we have this defined as below).
You can return an Object as a primary key - your case is a bit strange as your primary key object has only one field. In that case the spec would prefer you simply stick to that field in the bean itself(14.1.9).
Lets pretend this works (it might) - you will still have to include the virtual field public abstract String getSEventId(); public abstract void setSEventId(String sEventId); and the associated abstract schema definition on your CMT entity bean (220.127.116.11). However you would not specify <primkey-field> (this is standard practice for a compound primary key).
18.104.22.168 Primary key that maps to multiple fields in the entity bean class The primary key class must be public, and must have a public constructor with no parameters. All fields in the primary key class must be declared as public. The names of the fields in the primary key class must be a subset of the names of the container-managed fields. (This allows the container to extract the primary key fields from an instance�s container-managed fields, and vice versa.)
Originally posted by Raj Puri: To me seems this will be illegal as return type needs to be declared in DD.
I don't see a problem there - you just give the fully qualified name of your primary key class. <prim-key-class>FullyQualifiedPackage.CustPK</prim-key-class>
I am trying to use oracle sequence generator to generate next sequence that is used by the table as primary key here(custpk). The way to do it in oracle is that you send an insert omitting the PK column and backend insert trigger will generate the next sequence and Oracle will take care of PK. So kind of EJB is only responsible for all columns except PK. So code returns a null key.
This used to work fine with EJB 1.1 and now I get error like can not call getprimarykey() inside Ejbcreate see chapter 10.5.4 of EJB 2.0 specs. Really all Ejbcreate is doing is setting all columns and returning null as PK per specs.
Is there any clue on this? I have spent a number of hours reading on this.
37. How can I use a system generated primary key? If you specify java.lang.Object as the primary key class type in <prim-key-class>, but do not specify the primary key name in <primkey-field>, then the primary key is auto-generated by the container. OC4J names the corresponding database column as autoid by default.
38. Can I use a database sequence for a primary key? OC4J currently does not support a database sequence for primary key for CMP entity beans. You have to use a stateless session bean or a Java class to use a sequence to generate primary key for your CMP entity bean. The FAQ demo application shipped with OC4J has an example of PK Generator using a database sequence.
If you continue to use the trigger in the established fashion you are going to need an ejbLoad before your primary key is loaded. That is too late as the container needs the primary key to create the EJBObject before it calls ejbPostCreate.
The avenues I would pursue:
Modify the trigger to test whether the INSERT contains a primary key - and only provide one if it does not.
In the ejbCreate access the sequence yourself to obtain the primary key. You may be able to do it in the ejbCreate or in a helper method of the bean - you may have to access the sequence through a stateless session bean, possibly through a stored procedure.
[ October 09, 2005: Message edited by: Peer Reynders ]
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop