Which JPA annotation is used to define a column in a database table?

Java MCQ: Which JPA annotation is used to define a column in a database table?

a) @Table
b) @Field
c) @Column
d) @Mapping

Answer:

c) @Column

Explanation:

The @Column annotation in JPA is used to define a column in a database table. It is applied to a field or property of an entity class and specifies the name, type, and other properties of the corresponding column in the database.

Here’s an example:

@Entity
public class Employee {
    @Id
    private Long id;

    @Column(name = "emp_name")
    private String name;

    // Getters and setters
}

In this example, the @Column(name = "emp_name") annotation specifies that the name field should be mapped to the emp_name column in the database table.

The @Column annotation provides a way to customize the mapping between an entity field and the database column.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top