Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Steve Buck
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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 ]
 
Damanjit Kaur
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • 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.
 
Sudhir V
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • 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>
 
Pay attention! Tiny ad!
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!