pessoal, nao estou entendendo como usar a annotation GeneratedValue e os argumentos dela. alguem pode me explicar ?
Dá uma olhada nesse site:
http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html
http://www.hibernate.org/hib_docs/annotations/reference/en/html/index.html
O q posso adiantar a vc é q um annotation q dentre as diversas funções possibilita mapeamento a chaves primárias geradas automaticamente pelo banco (sequences).
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Pessoa
{
@Id
@Column (insertable = false)
@GeneratedValue (strategy = GenerationType.SEQUENCE, generator = "pessoa_id_seq")
private int id;
private String nome;
@OneToMany( cascade = { CascadeType.PERSIST })
private List<Endereco> enderecos = new ArrayList<Endereco>();
@OneToMany( cascade = { CascadeType.PERSIST })
private List<Contato> contatos = new ArrayList<Contato>();
@OneToMany( cascade = { CascadeType.PERSIST })
private List<Documento> documentos = new ArrayList<Documento>();
public int getId()
{
return id;
}
...
}
Esse texto foi retirado da especificação JPA, acho que pode ajudar:
[quote]The GeneratedValue annotation provides for the specification of generation strategies for the values
of primary keys. The GeneratedValue annotation may be applied to a primary key property or
field of an entity or mapped superclass in conjunction with the Id annotation. [43]
Table 9 lists the annotation elements that may be specified for a GeneratedValue annotation and
their default values.
The types of primary key generation are defined by the GenerationType enum:
public enum GenerationType { TABLE, SEQUENCE, IDENTITY, AUTO };
The TABLE generator type value indicates that the persistence provider must assign primary keys for
the entity using an underlying database table to ensure uniqueness.
The SEQUENCE and IDENTITY values specify the use of a database sequence or identity column,
respectively.
The AUTO value indicates that the persistence provider should pick an appropriate strategy for the particular
database. The AUTO generation strategy may expect a database resource to exist, or it may
attempt to create one. A vendor may provide documentation on how to create such resources in the
event that it does not support schema generation or cannot create the schema resource at runtime.[/quote]