Hibernate / Hibernate 7 Basics Interview Questions
What is an entity in Hibernate 7 and how do you define one?
An entity is a Java class mapped to a database table. Each instance corresponds to a row. In Hibernate 7, entity classes follow Jakarta Persistence 3.2 rules.
import jakarta.persistence.*; @Entity @Table(name = "products") public class Product { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "product_name", nullable = false, length = 200) private String name; @Column(precision = 10, scale = 2) private BigDecimal price; @Enumerated(EnumType.STRING) // store as 'ACTIVE' not 0/1 private ProductStatus status; protected Product() {} // JPA proxy constructor public Product(String name, BigDecimal price) { this.name = name; this.price = price; this.status = ProductStatus.ACTIVE; } }
More Related questions...