Quizzes@Entity, @Table, @Id — Concept Check
intermediate
hibernate

@Entity, @Table, @Id — Concept Check

Questions on @Entity, @Table, @Id. @Entity marks a class as a JPA-managed entity; @Table customises the table name and schema; @Id designates the primary key field; every entity must have exactly one @Id.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on @Entity, @Table, @Id — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A developer wants to map a Java class to a database table with a different name using JPA. Which annotation should they use?

    • A@Entity
    • B@Table
    • C@Id
    • D@Column
  2. 2.A class annotated with @Entity must have which of the following?

    • AMultiple @Id fields
    • BStatic methods
    • CA final class declaration
    • DA no-arg constructor
  3. 3.A developer uses @IdClass for composite keys. What is a potential downside?

    • ARequires no-arg constructor
    • BCannot use field access
    • CIncompatible with @Table
    • DLess type safety compared to @EmbeddedId
  4. 4.A developer mistakenly believes that @Entity automatically customizes the table name. What is the correct understanding?

    • A@Entity customizes the table name by default.
    • B@Entity registers a class as a JPA entity; @Table customizes the table name.
    • C@Entity and @Table both customize the table name.
    • D@Entity is not required for JPA mapping.
  5. 5.What happens if a JPA entity is missing an @Id annotation?

    • AThe entity will automatically generate a composite key.
    • BThe entity will map successfully without issues.
    • CThe application will fail at runtime due to missing primary key.
    • DThe entity will use a default primary key.
  6. 6.A developer uses @EmbeddedId for a composite key. What is a key advantage of this approach?

    • AAvoids using @Entity
    • BType safety
    • CSimpler JPQL queries
    • DNo need for equals/hashCode
  7. 7.A developer wants to enforce a unique constraint on a column using JPA. Which annotation should they use?

    • A@Column with unique
    • B@Id
    • C@Entity
    • D@Table with uniqueConstraints
  8. 8.A developer believes that @Id is optional if @GeneratedValue is used. What is the correct understanding?

    • A@Id is only needed for composite keys.
    • B@GeneratedValue replaces the need for @Id.
    • C@Id is optional if @GeneratedValue is present.
    • D@Id is mandatory for all entities, even with @GeneratedValue.