> I have to check that a name is unique before creating or updating this
> object. How can i do that without using a database constraint and
> without concurrency problem?
> The jboss pk-constraint tag set the constaints on the database, is there
> something to do the same thing managed by the container?
There may be a better way, and if so I'd like to hear about it.
What I did was create a finder method on the name and in the ejbCreate I call
the finder. If I get an ObjectNotFoundException I can continue to create,
otherwise I throw a DuplicateKeyException.
Here's an example:
/**
* @ejb:create-method
**/
public String ejbCreate(ContentNodeValue valueObject)
throws CreateException {
checkIfExists(valueObject.getName());
...
}
private void checkIfExists(String name) throws DuplicateKeyException {
<EJB_NAME>LocalHome home =
(<EJB_NAME>LocalHome) entityContext.getEJBLocalHome();
try {
<EJB_NAME>Local dup = home.findByName(name);
throw new DuplicateKeyException(
"A <EJB_NAME> with the name (" + name + ") already
exists");
} catch (ObjectNotFoundException e) {
//if object isn't found then we can create
} catch (FinderException e) {
throw new EJBException(e);
}
}
Jason
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user