SóProvas


ID
1689835
Banca
NC-UFPR
Órgão
COPEL
Ano
2015
Provas
Disciplina
Programação
Assuntos

Em relação ao mapeamento objeto-relacional usando JPA (Java Persistence API) 2.0, assinale a alternativa correta.

Alternativas
Comentários
  • Explicação da Alternativa C:

    The Sequence Strategy

    The sequence strategy consists of two parts - defining a named sequence and using the named sequence in one or more fields in one or more classes. The @SequenceGenerator annotation is used to define a sequence and accepts a name, an initial value (the default is 1) and an allocation size (the default is 50). A sequence is global to the application and can be used by one or more fields in one or more classes. The SEQUENCE strategy is used in the @GeneratedValue annotation to attach the given field to the previously defined named sequence:

    @Entity // Define a sequence - might also be in another class: 
    @SequenceGenerator(name="seq", initialValue=1, allocationSize=100) 
    public class EntityWithSequenceId { // Use the sequence that is defined above: @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq") @Id long id; }

    Unlike AUTO and IDENTITY, the SEQUENCE strategy generates an automatic value as soon as a new entity object is persisted (i.e. before commit). This may be useful when the primary key value is needed earlier. To minimize round trips to the database server, IDs are allocated in groups. The number of IDs in each allocation is specified by the allocationSize attribute. It is possible that some of the IDs in a given allocation will not be used. Therefore, this strategy does not guarantee there will be no gaps in sequence values.


  • c-

    Annotations do JPA

     

    @Entity – classe como entidade e tabela;
    @Table – Referencia o nome da tabela. somente quando o nome da tabela será diferente do nome da classe;
    @Id – atributo como chave primária;
    @Temporal – atributo tipo datetime;
    @GeneratedValue – com a anotação @Id, determinando geração deste valor;
    @Column – coluna no banco de dados.