1.EmployeeEntity class
@Entity
@Table(name = "Employee")
public class EmployeeEntitys {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", unique = true, nullable = false)
private Integer employeeId;//Integer
@Column(name = "EMAIL", unique = true, nullable = false, length = 100)
private String email;
@Column(name = "FIRST_NAME", unique = false, nullable = false, length = 100)
private String firstName;
@Column(name = "LAST_NAME", unique = false, nullable = false, length = 100)
private String lastName;
@OneToOne(cascade=CascadeType.ALL)//, fetch=FetchType.EAGER
private AccountEntity account;
public EmployeeEntitys() {
}
public EmployeeEntitys(Integer employeeId, String email, String firstName, String lastName) {
super();
this.employeeId = employeeId;
this.email = email;
this.firstName = firstName;
this.lastName = lastName;
}
public Integer getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Integer employeeId) {
this.employeeId = employeeId;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
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;
}
@Override
public String toString() {
return "EmployeeEntitys [employeeId=" + employeeId + ", email=" + email + ", firstName=" + firstName
+ ", lastName=" + lastName + ", account=" + account + "]";
}
public AccountEntity getAccount() {
return account;
}
public void setAccount(AccountEntity account) {
this.account = account;
}
}
2.Accountity class:
package com.dxc.OneToOne.Bidirectional;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@Entity
@Table(name = "ACCOUNT")
public class AccountEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ACCOUNT_ID", unique = true, nullable = false)
private Integer accountId;
@Column(name = "ACC_NUMBER", unique = true, nullable = false, length = 100)
private String accountNumber;
@OneToOne(mappedBy = "account",cascade=CascadeType.ALL)// fetch = FetchType.EAGER
private EmployeeEntitys employee;
public AccountEntity() {
}
public AccountEntity(Integer accountId, String accountNumber) {
super();
this.accountId = accountId;
this.accountNumber = accountNumber;
}
public EmployeeEntitys getEmployee() {
return employee;
}
public void setEmployee(EmployeeEntitys employee) {
this.employee = employee;
}
public Integer getAccountId() {
return accountId;
}
public void setAccountId(Integer accountId) {
this.accountId = accountId;
}
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
}
Я создал два вышеупомянутых класса сущностей, и мой сервер работал нормально, и я использую базу данных h2, и я могу сохранить данные с помощью CurdRepository, но всякий раз, когда я используя метод findAll (), он дает приведенную ниже ошибку
в com.faster xml .jackson.databind.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [jackson-databind -2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanSerializer.serialize (BeanSerializer. java: 155) ~ [jackson-databind-2.9.5.jar: 2.9 .5] на com.faster xml .jackson.databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter. java: 727) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind .ser.BeanSerializer.serialize (BeanSerializer. java: 155) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter. java: 727) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser. std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanSerializer.serialize (BeanSerializer. java: 155) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter. java: 727) ~ [ jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [jackson-databind-2.9. 5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanSerializer.serialize (BeanSerializer. java: 155) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter. java: 727) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml. jackson.databi nd.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanSerializer. serialize (BeanSerializer. java: 155) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter. java: 727) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [jackson- databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanSerializer.serialize (BeanSerializer. java: 155) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter. java: 727) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson. databind.ser.BeanSe rializer.serialize (BeanSerializer. java: 155) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter. java: 727) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [ jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanSerializer.serialize (BeanSerializer. java: 155) ~ [jackson-databind-2.9.5. jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter. java: 727) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com .faster xml .jackson.databind.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [jackson-databind-2.9.5.jar: 2.9.5] в com.faster xml. jackson.databind.ser.BeanSerializer.serialize (BeanSerializer. java: 155) ~ [jackson-databind-2.9.5.jar: 2.9.5] в com.faster xml .jackson.databind.ser.BeanPropertyWriter. serializeAsField (BeanPropertyWriter. java: 727) ~ [jackson-databind-2.9.5.jar: 2.9.5] в com.faster xml .jackson.databind.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanSerializer.serialize (BeanSerializer. java: 155) ~ [jackson- databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter. java: 727) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.std.BeanSerializerBase.serializeFields (BeanSerializerBase. java: 719) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com .faster xml .jackson.databind.ser.BeanSerializer.serialize (BeanSerializer. java: 155) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson. databind.ser.BeanPropertyWriter.serializeAsField (BeanPropertyWriter. java: 727) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.std.BeanSerializerBase. serializeFie lds (BeanSerializerBase. java: 719) ~ [jackson-databind-2.9.5.jar: 2.9.5] на com.faster xml .jackson.databind.ser.BeanSerializ