public interface class java.sql
AutoGeneratedKeys


Hide details Login
Java SE 6
  
Implements: Annotation
@Documented
@Retention(value=java.lang.annotation.RetentionPolicy.RUNTIME)
@Target(value=java.lang.annotation.ElementType.TYPE)

Annotation used to indicate that a DataSet returned by invoking a method decorated by the Update annotation is used to hold the columns which represent the returned. auto-generated keys. To return auto-generated keys, the keys annotation element will have a value of GeneratedKeys.RETURNED_KEYS_DRIVER_DEFINED or GeneratedKeys.RETURNED_KEYS_COLUMNS_SPECIFIED.

A data class that wishes to store auto-generated keys in a DataSet needs to annotate the data class with this marker annotation.

For example:

  @AutoGeneratedKeys
 public class myKeys {
    public String col1;
 }

 public interface MyQueries{
   @Update(sql="insert into tabName(?1, ?2)",
    keys=GeneratedKeys.RETURNED_KEYS_DRIVER_DEFINED) 
   DatSet<myKeys> addPerson(String name, int age);
 }

 

After a call to the annotated method, addPerson, the auto-generated keys if any are stored in the DataSet. The JDBC driver will determine which columns to return as the auto-generated key. If the data class, myKeys, is not annotated with the AutoGeneratedKeys annotation, then a SQLRuntimeException is thrown.
since1.6
See also java.sql.GeneratedKeys, executeUpdate(java.lang.String, java.lang.String []), executeUpdate(java.lang.String, int)