Hi Eric
            Well this is good to used db based sequence number as the primary key . I m currently using the mysql and its auto_increment sequence as primary key
But to use this feature u have to use jboss 3.2.03 beta ..As  unique sequence no is managed by the db not but the EJB container . so while inserted the new record . u dont have to pass the value for the unique sequence no.
Like u have a User Entity EJB
User have DB schema
 
userID int(11) auto_increment primary key  ----------------------- now this is acting as the primary key 
username varchar(30)
password varchar(30)
email varchar(30)
ur
 
ejbCreate(String username, String password, String email)
{
    //    here u havent provided the value of userID as it inserted by DB // it can any sequence no
}
ejbPostCreate(String username, String password, String email)
{
 
}
    Deployment decriptor entor
 
      <ejb-name>User</ejb-name>
      <local-home>com.n4i.ejb.test.UserLocalHome</local-home>
      <local>com.n4i.ejb.test.UserLocal</local>
      <ejb-class>com.n4i.ejb.test.UserBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>  // I m using int(11) as the primary key if ur using some unique string the specify java.lang.String
     <reentrant>False</reentrant>
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>User</abstract-schema-name>
      <cmp-field>
        <field-name>userID</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>username</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>password</field-name>
      </cmp-field>
      <cmp-field>
        <field-name>email</field-name>
      </cmp-field>
      <primkey-field>userID</primkey-field>
 
 
But u need to have getter and setter for this unique sequence no primary key field ... as its  getter method will be used when u call getUserID on local/Remote refernce of the entityBean .
// One thing that is to noted here .is userID field is managed by the DB not by EJB Container but have to declare in the deployment descriptor as CMP field
 
Eric this thing is working with mysql for mee .. in oracle if ur using sequence as primary key its value is integer .. and it will work tooo .
 
Rgds
 
Brijesh
 
 
----- Original Message -----
From: "Eric Tim" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 18, 2003 11:08 AM
Subject: [JBoss-user] CMP - Primary Key Strategies?

> I'm working on a CMP EntityBean with JBoss3 on
> Oracle8.
>
> My primary key must be a unique number. Oracle has a
> nice facility for handling sequences, which doesn't
> seam possible with this senerio because i'd need to
> write some jdbc code in the ejbCreate method to get
> the nextval.
>
> I'm aware that there are several J2EE
> patterns/blueprints to solve this...most have
> not-so-clean side effects that i'd like to
> avoid...such as extra tables..etc.
>
> Is there anything that i can do with JBoss to solve
> this problem in a simple and clean manner?
>
> Someone told me that there is a cmp engine that i can
> buy that plugs into jboss that makes this easy. Does
> anyone know what product this is? Does anyone have
> experience with it?
>
> thanks,
> -et
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
> http://platinum.yahoo.com
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by:Crypto Challenge is now open!
> Get cracking and register here for some mind boggling fun and
> the chance of winning an Apple iPod:
> http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user
>

Reply via email to