← Каталог
Hibernate и JPA — практический старт — Сущность
Фрагмент из «Hibernate и JPA — практический старт»: Сущность.
package com.example.notes;
import jakarta.persistence.*;
@Entity
@Table(name = "notes")
public class Note {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 500)
private String text;
protected Note() {}
public Note(String text) {
this.text = text;
}
public Long getId() { return id; }
public String getText() { return text; }
public void setText(String text) { this.text = text; }
} package com.example.notes;
import jakarta.persistence.*;
@Entity
@Table(name = "notes")
public class Note {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 500)
private String text;
protected Note() {}
public Note(String text) {
this.text = text;
}
public Long getId() { return id; }
public String getText() { return text; }
public void setText(String text) { this.text = text; }
}