Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unknown primary key class

 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Section 10.8.3 of the spec mentions about the Unknown Primary Key class. I am not able to understand this thoroughly. Specifically, the third paragraph:

When defining the primary key for the enterprise bean, the Deployer using the Container Provider´┐Żs tools will typically add additional container-managed fields to the concrete subclass of the entity bean
class (What does this mean??).
In this case, the Container must generate the primary key value when the entity bean instance is created (and before ejbPostCreate is invoked on the instance.) How does the container generate the primary key here??
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, the "typically add CM fields to the concrete subclass of the entity bean". Note this is a "typically" used way, but not mandatory, it may work with fields already in your abstract bean class. This strategy is to extend the bean class to add one field (or more) that will hold the primary key value. Then, describe in deployment descpriptor a way to generate a value for this field. This mechanism usually uses container-specific tools/features (and some times also DB-specific features).

Have a look at this :


Here you have jboss specific unknown pk class elements added to DD, to describe the new field, and outside of the enterprise-beans block, another specific feature describing tke PK value generator.

This example shows how to declare a new field (here JBOSS will add a new field of java.lang.Integer type to the bean subclass) and how the container generates the key value (it calls the generator class defined at the end to get a value for the PK).

Note that a generator is not necessary. Here is an example of PK generation examples in Geronimo EJB container :



Here any of the generator may be selected to get a PK value each time container needs one.

JBOSS also can use several ways to generate a key. Look this adress to see how it can do: JBOSS key generators

Hope it clarifies the thing.
 
Ankit Doshi
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it does clarify ...

This had been totally unexplored area for me ... anyway thanks for clarifying.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic