Re: [JBoss-user] cmp primary key fields
The same way as non primary key fields. Jeremy Rempel wrote: Hi, In jbosscmp-jdbc.xml how do I map primary key fields to a certain database field? I can map the regular fields easily. Thanks, Jeremy --- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] CMP - Primary Key Strategies?
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 User com.n4i.ejb.test.UserLocalHome com.n4i.ejb.test.UserLocal com.n4i.ejb.test.UserBean Container java.lang.Integer // I m using int(11) as the primary key if ur using some unique string the specify java.lang.String False 2.x User userID username password email userID 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>
RE: [JBoss-user] CMP - Primary Key Strategies?
I'm trying something different...to try to solve the same problem.and am using Oracle8. I have a trigger on the table set to fire "before INSERT" and set the id to the mySqeunce.nextval. But this doesn't seam to be working. On the entity bean that I get back i call getId and Jboss throws this exception: java.lang.IllegalArgumentException: Attempt to get a lock for a null object. The row however gets inserted properly. Does anyone know why this is the case? > -Original Message- > From: Rod Macpherson [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 18, 2003 1:43 PM > To: [EMAIL PROTECTED] > Subject: RE: [JBoss-user] CMP - Primary Key Strategies? > > > Consider a static interface createPrimaryKey() or > createPrimaryKey(String source) where source is a sequence name in the > oracle implementation. Use a pooled connection (needless to say) and > cache, say, a few dozen keys in memory. Alternatively you can > make your > sequence increment by, say, 100 and dish out keys until you > exhaust the > cache then grab another base value: high-low pattern as it is > sometimes > called. This strategy is portable insofar as you can have an > implementation for various RDBMSs but the rest of your code does not > change. The ejbCreate just calls createPrimaryKey and if anything goes > wrong you throw away that key. If you're server bounces you throw away > the cached keys, no biggie. > > > -Original Message- > From: Eric Tim [mailto:[EMAIL PROTECTED] > Sent: Monday, March 17, 2003 9:39 PM > To: [EMAIL PROTECTED] > 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 > > > --- > This SF.net email is sponsored by: Does your code think in ink? > You could win a Tablet PC. Get a free Tablet PC hat just for playing. > What are you waiting for? > http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en > ___ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user > This transmission contains information solely for intended recipient and may be privileged, confidential and/or otherwise protect from disclosure. If you are not the intended recipient, please contact the sender and delete all copies of this transmission. This message and/or the materials contained herein are not an offer to sell, or a solicitation of an offer to buy, any securities or other instruments. The information has been obtained or derived from sources believed by us to be reliable, but we do not represent that it is accurate or complete. Any opinions or estimates contained in this information constitute our judgment as of this date and are subject to change without notice. Any information you share with us will be used in the operation of our business, and we do not request and do not want any material, nonpublic information. Absent an express prior written agreement, we are not agreeing to treat any information confidentially and will use any and all information and reserve the right to publish or disclose any information you share with us. --- This SF.net email is sponsored by: Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for? http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
RE: [JBoss-user] CMP - Primary Key Strategies?
Consider a static interface createPrimaryKey() or createPrimaryKey(String source) where source is a sequence name in the oracle implementation. Use a pooled connection (needless to say) and cache, say, a few dozen keys in memory. Alternatively you can make your sequence increment by, say, 100 and dish out keys until you exhaust the cache then grab another base value: high-low pattern as it is sometimes called. This strategy is portable insofar as you can have an implementation for various RDBMSs but the rest of your code does not change. The ejbCreate just calls createPrimaryKey and if anything goes wrong you throw away that key. If you're server bounces you throw away the cached keys, no biggie. -Original Message- From: Eric Tim [mailto:[EMAIL PROTECTED] Sent: Monday, March 17, 2003 9:39 PM To: [EMAIL PROTECTED] 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 --- This SF.net email is sponsored by: Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for? http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] CMP - Primary Key Strategies?
On Tuesday, March 18, 2003, at 12:54 AM, Rafal Kedziorski wrote: hi, At 23:33 17.03.2003 -0800, Matthew Hixson wrote: On Monday, March 17, 2003, at 09:38 PM, Eric Tim wrote: 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. In Postgres we get the value for the PK from a sequence by doing the following. create sequence manufacturers_sequence; create table manufacturers( manufacturer_id integer default nextval('manufacturers_sequence') primary key, manufacturer_name varchar(100) not null); Can you do something like that in Oracle when you create the table for the bean? Or are you letting JBoss create the table and it doesn't know how to put the 'default nextval...' snippet into the 'create table' command? but after creating new entity bean with CMP you have to know your primary key. is this possible with JBoss 3.0.6? The call to create() on your entity bean's local or remote home interface should return a reference to either the local or remote interface of your bean and you should be able to ask it for its primary key. The PK does not need to be known before you can create an entity bean. -M@ --- This SF.net email is sponsored by: Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for? http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] CMP - Primary Key Strategies?
hi, At 23:33 17.03.2003 -0800, Matthew Hixson wrote: On Monday, March 17, 2003, at 09:38 PM, Eric Tim wrote: 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. In Postgres we get the value for the PK from a sequence by doing the following. create sequence manufacturers_sequence; create table manufacturers( manufacturer_id integer default nextval('manufacturers_sequence') primary key, manufacturer_name varchar(100) not null); Can you do something like that in Oracle when you create the table for the bean? Or are you letting JBoss create the table and it doesn't know how to put the 'default nextval...' snippet into the 'create table' command? but after creating new entity bean with CMP you have to know your primary key. is this possible with JBoss 3.0.6? rafal --- This SF.net email is sponsored by: Does your code think in ink? You could win a Tablet PC. Get a free Tablet PC hat just for playing. What are you waiting for? http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] CMP - Primary Key Strategies?
On Monday, March 17, 2003, at 09:38 PM, Eric Tim wrote: 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. In Postgres we get the value for the PK from a sequence by doing the following. create sequence manufacturers_sequence; create table manufacturers( manufacturer_id integer default nextval('manufacturers_sequence') primary key, manufacturer_name varchar(100) not null); Can you do something like that in Oracle when you create the table for the bean? Or are you letting JBoss create the table and it doesn't know how to put the 'default nextval...' snippet into the 'create table' command? -M@ 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 --- 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
RE: [JBoss-user] CMP - Primary Key Strategies?
With JBoss 3.2 there is now a PkSQL entity-command that can be used to issue arbitrary SQL to obtain a new PK value. This could be used to obtain a value from the sequence. > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Eric Tim > Sent: Monday, March 17, 2003 9:39 PM > To: [EMAIL PROTECTED] > 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/j> boss-user > --- 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
Re: [JBoss-user] cmp primary key
I have implemented the primary key pattern described in that (The) Server Side article. If anyone would like the source code for this, please email me off-list for a copy. ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] cmp primary key
I usually use a counter entity bean. The entity bean's PK is a string, which uniquely names the counter. It has a method called, "getNextValue", which returns a long incrementing from zero. This may not be the fastest way, but it's very simple, and you will never get a duplicate (unless you've exhausted all 2^64 values.) If wrap-around is a concern, you can always make it into a string, and append the date. This way, you'd have to use up all 2^64 values in one day before the value would repeat. Mike - Original Message - From: "Frank Morton" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, October 15, 2001 11:40 AM Subject: [JBoss-user] cmp primary key > I'm a newbie for sure, but I've been surfing around for > a solution to assigning unique primary key values with > CMPs. I have seen lots of vague descriptions of how > to do it and some specific ones that are all followed by > other comments from people why that solution doesn't > work. > > Does anyone have a specific solution and the complete > code to do this they can share? This seems like it must > be a very common problem that ought to have a standard > solution. > > Help. I'm really getting frustrated. > > Frank > > > > ___ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user > ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
RE: [JBoss-user] cmp primary key
Frank, I have found that it is the easiest to use a UUID that combines the time with some random number in a java Long object. These values are so ridiculously big that it is almost impossible to get a duplicate key, but of course you have to make arrangements in your code to catch the DuplicateKeyException and generate a new key, but I can assure you that this will not happen often... Joost. -Original Message- From: Frank Morton [mailto:[EMAIL PROTECTED]] Sent: Monday, October 15, 2001 7:40 PM To: [EMAIL PROTECTED] Subject: [JBoss-user] cmp primary key I'm a newbie for sure, but I've been surfing around for a solution to assigning unique primary key values with CMPs. I have seen lots of vague descriptions of how to do it and some specific ones that are all followed by other comments from people why that solution doesn't work. Does anyone have a specific solution and the complete code to do this they can share? This seems like it must be a very common problem that ought to have a standard solution. Help. I'm really getting frustrated. Frank ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] cmp primary key
You should have a look at EJBUtils: http://sourceforge.net/projects/ejbutils/ Nguyen Thanh Phong Tel: 84-8-837 25 06/837 25 07 Saigon Software Development Company (SDC)Fax: 84-8-837 25 11 10 Co Giang Street, Dist I, HCMC Email: [EMAIL PROTECTED] Vietnam - Original Message - From: "Frank Morton" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, October 16, 2001 12:40 AM Subject: [JBoss-user] cmp primary key > I'm a newbie for sure, but I've been surfing around for > a solution to assigning unique primary key values with > CMPs. I have seen lots of vague descriptions of how > to do it and some specific ones that are all followed by > other comments from people why that solution doesn't > work. > > Does anyone have a specific solution and the complete > code to do this they can share? This seems like it must > be a very common problem that ought to have a standard > solution. > > Help. I'm really getting frustrated. > > Frank > > > > ___ > JBoss-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/jboss-user > ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user
RE: [JBoss-user] cmp primary key
Title: RE: [JBoss-user] cmp primary key In CMP, in the ejbCreate(), you must generate the key and assign it to the primary key field of your bean. The strategy of generating the PK depends on your context. 1. If the PK is a string You can use a UUID generator to generate a key of 32 character. That key will be unique within the application server network. (This is portable to all app server and database). I have an implementation of it that Im using for my app, If u need it, jut contact me 2. If the PK is int or long - If your database supports sequences, you create 1 sequence per entity bean in the database. in ejbCreate(), request the next value of the sequence via a JDBC call. (This is not portable to all db. PostgreSQL, Orable supports sequences) - Use a SessionBean for generating the unique key. See http://www.theserverside.com/patterns/thread.jsp?thread_id=220 See also http://www.theserverside.com/resources/patterns_review.jsp (Primary Key Generation Strategies) -Original Message- From: Frank Morton [mailto:[EMAIL PROTECTED]] Sent: Monday, October 15, 2001 1:40 PM To: [EMAIL PROTECTED] Subject: [JBoss-user] cmp primary key I'm a newbie for sure, but I've been surfing around for a solution to assigning unique primary key values with CMPs. I have seen lots of vague descriptions of how to do it and some specific ones that are all followed by other comments from people why that solution doesn't work. Does anyone have a specific solution and the complete code to do this they can share? This seems like it must be a very common problem that ought to have a standard solution. Help. I'm really getting frustrated. Frank ___ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user