Performance: Column mapping with @Column
This affects how the database columns are mapped to Java entity fields, impacting query efficiency and ORM behavior during data loading and saving.
Jump into concepts and practice - no test required
public class User { @Column(name = "username", nullable = false) private String username; @Column(name = "password", nullable = false) private String password; @Lob @Basic(fetch = FetchType.LAZY) @Column(name = "large_text_field", columnDefinition = "TEXT") private String largeTextField; }
public class User {
@Column
private String username;
@Column
private String password;
@Column
private String largeTextField;
}| Pattern | Initial Columns Fetched | Data Volume | Memory Usage | Verdict |
|---|---|---|---|---|
| Basic @Column without fetch control | All columns | High | High | [X] Bad |
| @Column with explicit name and lazy fetch | Essential columns | Low | Low | [OK] Good |
@Column annotation in Spring Boot?@Column?@Column(name = "email", unique = true, nullable = false) private String email;
@Column(name = "age", nullable = false) private Integer age;
age = null without error?private String phoneNumber; to a database column named phone_num that must be unique and cannot be null, with a maximum length of 15 characters. Which is the correct @Column annotation to use?