SóProvas


ID
1452508
Banca
CESPE / CEBRASPE
Órgão
TRE-GO
Ano
2015
Provas
Disciplina
Programação
Assuntos

Com relação à JPA (Java persistence API), julgue o item subsequente.

A anotação @Entity significa que determinada classe Java é uma entidade do banco de dados. Caso essa entidade tenha nome que não seja o da tabela, será necessário utilizar a anotação @Table.

Alternativas
Comentários
  • http://www.tutorialspoint.com/hibernate/hibernate_annotations.htm

    @Entity Annotation:

    The EJB 3 standard annotations are contained in the javax.persistence package, so we import this package as the first step. Second we used the @Entity annotation to the Employee class which marks this class as an entity bean, so it must have a no-argument constructor that is visible with at least protected scope.

    @Table Annotation:

    The @Table annotation allows you to specify the details of the table that will be used to persist the entity in the database.

    The @Table annotation provides four attributes, allowing you to override the name of the table, its catalogue, and its schema, and enforce unique constraints on columns in the table. For now we are using just table name which is EMPLOYEE.



  • Correta, porém, o atributo "name" da anotação @Table deve ser informado com o nome da tabela.

  • Se necessitarmos definir o nome de uma tabela, utilizamos a notação @Table, de javax.persistence.Table. O mesmo também pode ser feito para dar nomes a colunas, utilizando a anotação @Column, de javax.persistence.Column.

    http://imasters.com.br/artigo/16562/java/jpa-20-na-pratica-conhecendo-as-anotacoes-em-uma-entidade/

  • A questão não especificou se é para colocar somente a anotação @Table. Isso torna a questão correta.
    Segue um exemplo abaixo do uso da notação @Table quando o nome da tabela no banco for diferente ao da entidade JPA:

    @Entity
    @Table(name="TB_CARRO")
    public class Carro {
    }