How to implement an entity bean which the PrimaryKey is an autonumeric

Showing Answers 1 - 2 of 2 Answers

Ginni Gandhi

  • Jul 20th, 2005
 

If you mean, auto generated primary key with values as numeric. This can be acheived in EJB 2.0 by using tag. You need to define and to specify how the keys are generated.  
If generation type is 'ORACLE', generation-name should be the Oracle sequence name. 
IF generation-type is 'NAMED_SEQUENCE_TABLE', generation-name should be the name of table that cotain 1 coloum by the name SEQUENCE of type INT

  Was this answer useful?  Yes

Ananda

  • Jan 27th, 2006
 

It is required by the EJB specification that the Container should be able to automatically generate unique primary keys using Object as key for CMP Entity beans. This is very useful when you don't need to show the primary key to the client or have the client select a primary key.

In order for the Container to generate primary keys for an CMP Entity the following is required:

The ejbCreate method should have a return type of java.lang.Object and return null.

The <persistence-type> tag should contain a value of Container in the ejb-jar.xml entry for the entity

The <prim-key-class> tag should contain a value of java.lang.Object in the ejb-jar.xml entry for the entity

The <primkey-field> should not be given in the ejb-jar.xml entry for the entity

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions