• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Where/how is the primary key defined a BMP bean?

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm curious how the primary key is denoted.

I see methods using things like EntityContex.getPrimaryKey() for the current entity object, but I don't understand--how/where is the primary key defined? They just all look like regular instance variables in the class...

I know that any "unique" value of the database/store can be a primary key, but how does J2EE know which field you are even talking about?

As far as I can tell (reviewing some samples) it is never stated in any of the methods like ejbCreate, ejbStore, ejbLoad etc. So I'm a little confused
[ December 08, 2004: Message edited by: Steve Buck ]
 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

EntityContext returns an object which is of type xxxPK class(where xxx is name of bean). this class instances has hashcodes pointers to each database records, corresponding to each primary key. The primary key is the field(variable that we define in xxxPK class) and which is mapped to its corresponding field in database table.

This is the way I understood it.
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The primary key is defined in the ejb-jar.xml and is denoted by the tag
<primkey-field>cmp field name</primkey-field> under the entity tag.

The actual mapping between the cmp field names and actual table columns is not specified as a specification in the J2EE hence each app server has its own methodology. Weblogic stores another xml file called "weblogic-cmp-rdbms-jar" where it sepcifies the mapping. Below is an excerpt

<weblogic-rdbms-jar>
<weblogic-rdbms-bean>
<ejb-name>RoomTypeEJB</ejb-name>
<data-source-name>BigRezDataSource</data-source-name>
<table-map>
<table-name>ROOMTYPE</table-name>
<field-map>
<cmp-field>description</cmp-field>
<dbms-column>DESCRIPTION</dbms-column>
</field-map>
<field-map>
<cmp-field>features</cmp-field>
<dbms-column>FEATURES</dbms-column>
</field-map>
<field-map>
<cmp-field>id</cmp-field>
<dbms-column>ID</dbms-column>
</field-map>
<field-map>
<cmp-field>maxAdults</cmp-field>
<dbms-column>MAXADULTS</dbms-column>
</field-map>
<field-map>
<cmp-field>numRooms</cmp-field>
<dbms-column>NUMROOMS</dbms-column>
</field-map>
<field-map>
<cmp-field>smokingFlag</cmp-field>
<dbms-column>SMOKINGFLAG</dbms-column>
</field-map>
</table-map>
<automatic-key-generation>
<generator-type>NAMED_SEQUENCE_TABLE</generator-type>
<generator-name>COMMON_SEQUENCE</generator-name>
<key-cache-size>1</key-cache-size>
</automatic-key-generation>
</weblogic-rdbms-bean>
<weblogic-rdbms-jar>
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic