[EMAIL PROTECTED] wrote:
> 
> How about using some creative SQL like:
> 
> pStatement = con.prepareStatement(
>          "Insert into Attribute " +
>          "(ID, Value, Display_Format, Attribute_Switches, Name,  Type_ID) " +
>          "Select max(id)+1, ?, ?, ?, ?, ? from Container ");
> 
> pStatement.setString(1, value);
> pStatement.setString(1, displayFormat);
> pStatement.setLong  (2, attributeSwitches);
> pStatement.setString(1, name);
> pStatement.setInt   (2, typeID);
> 
> if (pStatement.executeUpdate() != 1)
> {
>      throw new CreateException(...
> }

  //now return the primary key...
  return new Integer(???);

> 
> Just fill in the parameters with your values and the SQL statement is executed
> all at once.
> Wouldn't most, if not all, databases handle concurrancy issues in this case?
Yep! by locking every row in the table, either individually or by
escalating to a table lock. This approach is fine if you don't expect
too many creates of that bean, and you can get your primary key value
back so that you don't have to lie to the container (another select max
might work)

-danch
Confidential e-mail for addressee only.  Access to this e-mail by anyone else is 
unauthorized.
If you have received this message in error, please notify the sender immediately by 
reply e-mail 
and destroy the original communication.


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to