Dain:

First of all thanks for your interest, its an Honor.

Well, Alternate key is like a primary key, its just another key. For example if we use a surrogate key (generated artificial keys) for people/person then Social security number would become an alternate key or if we have Userid as unique key it would also be an Alternate key. Anything that is candidate for a primary but is not chosen to be PK becomes an alternate key and thus can also be NULL/changeable over time but UNIQUE.

The situation I have is of a Unique Key. When I call the set method on the CMP field with a non-unique I get javax.ejb.EJBException: Store failed; CausedByException is:

Invalid argument value: Duplicate entry 'test' for key 2, which actually is thrown to the container not to the caller on the method so it can not be trapped and processed or even interpreted.

What I have done is made custom method over the CMP filed so I can check if the new value is unique or not before actually calling the CMP set method. It does work but it has to make two trips to the DB when it could be done with one the other major problem is that while I check and set the filed/column some other instance can take/use the checked unique value as there is no lock on the table and the caller would not know as the javax.ejb.EJBException is not thrown to the caller but to the container. DB’s typically use indexes and lock the full index as to prevent this.

I think we need to some how or the other have to indicate to the persistent manager in the jbosscmp-jdbc.xml the fileds which are unique similar to not-null and also tell the container in the mapping that which actual SQLExceptions are thrown to be mapped to these conditions so the solution is independent of a DB provider and then proper Exception should be throws when set methods are called on these fields.

Let me know of your thoughts on this and also how I can help in implementing this.

-Asif Rafiq Ahmed.

 

Example code:

public void setFullURL(String newFullURL) throws UniqueKeyException {

if(newFullURL!=null && !newFullURL.equals("")){

try{

((LocalOrganizationHome)this.entityContext.getEJBLocalHome()).findByFullURLIgnoreSelf(newFullURL,(LocalOrganization)this.entityContext.getEJBLocalObject());

throw new UniqueKeyException("URL already used");

}

catch(FinderException fe){

this.setFullURLCmp(newFullURL);

}

}

}

 

 

.

 

 

 

 

 

 






***************************************************
Asif R. Ahmed.
2954 WEALD WAY# 2721
SACRAMENTO, CA 95833
Day Phone: (916) 730-6831
Even Phone:(916) 924-8786
***************************************************
From: Dain Sundstrom <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: [JBoss-user] Howto handle Alternate keys in EJB 2.0 CMP
Date: Sat, 27 Jul 2002 18:59:29 -0500
What is an Alternate key?
-dain
Asif R. Ahmed wrote:
>All:
> Has anybody an Idea how to handle the Alternate keys elegantly as
>the Primary Keys are handles in ejb2.0.
> What is an elegant solution to handle alternate keys in ejb2.0
>using cmp. When I set a CMP field which represents an alternate key
>to a already existing value I get javax.ejb.EJBException which has
>source exception of java.sql.SQLException which can be any db error.
> I would appreciate an Idea or even an Hint.
> Thanks in Advance,
> -Asif Rafiq Ahmed
>
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user


Chat with friends online, try MSN Messenger: Click Here
------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ JBoss-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to