У меня эти сущности в весенней загрузке как ниже
@Entity
@Table(name = "invoice")
public class Invoice {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "invoice_id")
long id;
String recipient;
String sender;
String issueDate;
boolean isApproved;
String status;
String blockchainTx;
String UUID;
boolean miningStatus;
@CreationTimestamp
private LocalDateTime createDateTime;
@UpdateTimestamp
private LocalDateTime updateDateTime;
@ManyToOne
@JoinColumn(name = "user_id")
Users user;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "invoice")
List<Item> invoiceItems = new ArrayList<Item>();
public Invoice() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getRecipient() {
return recipient;
}
public void setRecipient(String recipient) {
this.recipient = recipient;
}
public String getSender() {
return sender;
}
public void setSender(String sender) {
this.sender = sender;
}
public String getIssueDate() {
return issueDate;
}
public void setIssueDate(String issueDate) {
this.issueDate = issueDate;
}
public boolean isApproved() {
return isApproved;
}
public void setApproved(boolean approved) {
isApproved = approved;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getBlockchainTx() {
return blockchainTx;
}
public void setBlockchainTx(String blockchainTx) {
this.blockchainTx = blockchainTx;
}
public String getUUID() {
return UUID;
}
public void setUUID(String UUID) {
this.UUID = UUID;
}
public boolean isMiningStatus() {
return miningStatus;
}
public void setMiningStatus(boolean miningStatus) {
this.miningStatus = miningStatus;
}
public LocalDateTime getCreateDateTime() {
return createDateTime;
}
public void setCreateDateTime(LocalDateTime createDateTime) {
this.createDateTime = createDateTime;
}
public LocalDateTime getUpdateDateTime() {
return updateDateTime;
}
public void setUpdateDateTime(LocalDateTime updateDateTime) {
this.updateDateTime = updateDateTime;
}
public Users getUser() {
return user;
}
public void setUser(Users user) {
this.user = user;
}
public List<Item> getInvoiceItems() {
return invoiceItems;
}
public void setInvoiceItems(List<Item> invoiceItems) {
this.invoiceItems = invoiceItems;
}
}
И
@Entity
@Table(name = "invoice_item")
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "invoice_item_id")
long id;
@OneToOne
@JoinColumn(name = "product_id")
Product product;
int quantity;
double price;
String currency;
@OneToOne
Invoice invoice;
@CreationTimestamp
private LocalDateTime createDateTime;
@UpdateTimestamp
private LocalDateTime updateDateTime;
public Item() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public Invoice getInvoice() {
return invoice;
}
public void setInvoice(Invoice invoice) {
this.invoice = invoice;
}
public LocalDateTime getCreateDateTime() {
return createDateTime;
}
public void setCreateDateTime(LocalDateTime createDateTime) {
this.createDateTime = createDateTime;
}
public LocalDateTime getUpdateDateTime() {
return updateDateTime;
}
public void setUpdateDateTime(LocalDateTime updateDateTime) {
this.updateDateTime = updateDateTime;
}
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
}
И
@Entity
public class Product {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name = "product_id")
long id;
String SKU;
String productName;
String description;
String currency;
double price;
String unit;
int stock;
int tax;
@ManyToOne
@JsonIgnore
private Users user;
public Product() {
super();
}
public Product(String productName, String description, String currency, double price, String unit, int stock, String SKU, int tax) {
super();
this.productName = productName;
this.description = description;
this.currency = currency;
this.price = price;
this.unit = unit;
this.stock = stock;
this.SKU = SKU;
this.tax = tax;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
public Users getUser() {
return user;
}
public void setUser(Users user) {
this.user = user;
}
public String getSKU() {
return SKU;
}
public void setSKU(String SKU) {
this.SKU = SKU;
}
public int getTax() {
return tax;
}
public void setTax(int tax) {
this.tax = tax;
}
}
И пользователь
@Entity
@Table(name = "user")
public class Users {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name = "user_id")
private int id;
@Column(name = "email")
private String email;
@Column(name = "password")
private String password;
@Column(name = "name")
private String name;
@Column(name = "last_name")
@JsonAlias("last_name")
private String lastName;
@Column(name = "active")
private int active;
@CreationTimestamp
private LocalDateTime createDateTime;
@UpdateTimestamp
private LocalDateTime updateDateTime;
public Users() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public int getActive() {
return active;
}
public void setActive(int active) {
this.active = active;
}
}
Пока я звоню
Optional<Invoice> invoice = invoiceRepository.findById(id);
Я получаю
Unable to evaluate the expression Method threw 'org.hibernate.exception.GenericJDBCException' exception.
В массиве элементов счета в сущности Invoice.Но прошивка работает нормально.
Также, когда я впервые написал это, он делает что-то странное, он работал нормально, и я не понимаю, что я изменил, он совсем не работает.
Я подозреваю, что это проблема с отложенной загрузкой, и я тоже попытался вызвать размер в списке массивов, но безуспешно.
Пожалуйста, помогите мне.