User.java
package com.example.restapi.model;
import jakarta.persistence.*;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private String password;
private String fullName;
private String email;
//@OneToMany(mappedBy = "user")
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
@JsonIgnore // Prevents JSON serialization issues
private List<Borrowing> borrowedBooks;
public User() {}
public User(String username, String password, String fullName, String email) {
this.username = username;
this.password = password;
this.fullName = fullName;
this.email = email;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public List<Borrowing> getBorrowedBooks() {
return borrowedBooks;
}
public void setBorrowedBooks(List<Borrowing> borrowedBooks) {
this.borrowedBooks = borrowedBooks;
}
}