package crystal;
import javax.persistence.*;
@Entity
@Table(name = "NOTE")
public class Note {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
@Column(name = "TEXT")
private String text;
@ManyToOne
@JoinColumn(name = "AUTHOR_ID")
private Author author;
public Note() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public Author getAuthor() {
return author;
}
public void setAuthor(Author author) {
this.author = author;
}
@Override
public String toString() {
return String.format("Note{id=%d, text='%s', author='%s'}", id, text, author);
}
}
package crystal;
import javax.persistence.*;
import java.util.Set;
@Entity
@Table(name = "AUTHOR")
public class Author {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
@Column(name = "FIRST_NAME")
private String firstName;
@Column(name = "LAST_NAME")
private String lastName;
@OneToMany
@JoinColumn(name = "AUTHOR_ID")
private Set<Note> notes;
public Author() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Set<Note> getNotes() {
return notes;
}
public void setNotes(Set<Note> notes) {
this.notes = notes;
}
@Override
public String toString() {
return String.format("Author{id=%d, firstName='%s', lastName='%s'}", id, firstName, lastName);
}
}