@Retention(value=RUNTIME) @Target(value=TYPE) public @interface PrimaryKey
The names of the primary key properties are passed as a String. You must use Java capitalization conventions.
Here is a typical example:
@PrimaryKey("id") public class Customer { private int id; private String firstName; private String lastName; public int getId() { return id; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public void setId(int i) { id = i; } public void setFirstName(String s) { firstName = s; } public void setLastName(String s) { lastName = s; } }
In the typical case, as shown above, id
is the primary key.
Whenever the primary key is an int
or a long
,
GenericDAO
will create an auto-increment field to store the
key and GenericDAO
will let the database generate the value
when rows are created (using create()
).
Properties of composite keys must be listed in order, comma separated:
@PrimaryKey("lastName,firstName") public class AddressBookEntry { private String firstName; private String lastName; ... }
public abstract String value
Copyright © 2012-2016 Jeffrey L. Eppinger. All rights reserved. Permission granted for educational use only.