У меня есть родительско-дочерние отношения между сущностями MyUser и Circuit.Когда я пытаюсь сохранить MyUser, используя myUserRepository.save (myUser) , я получаю следующую ошибку:
org.hibernate.InstantiationException: Cannot instantiate abstract class or interface: : java.util.List
at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:79) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.tuple.component.AbstractComponentTuplizer.instantiate(AbstractComponentTuplizer.java:84) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.type.ComponentType.instantiate(ComponentType.java:580) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.type.ComponentType.deepCopy(ComponentType.java:500) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.type.ComponentType.deepCopy(ComponentType.java:497) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
at org.hibernate.type.TypeHelper.deepCopy(TypeHelper.java:54) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
Вот обе сущности:
MyUser:
@Entity
@Data
public class MyUser {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
@NotBlank
private String firstName;
@NotNull
private String lastName;
@NotNull
@Email
@Column(unique = true)
private String email;
@NotBlank
private String password;
private String chargeBeeCustomerID;
private String company = null;
@Enumerated(EnumType.STRING)
private UsagePurpose usagePurpose = null;
@Enumerated(EnumType.STRING)
private CountryCode countryCode = null;
private Instant createdAt = Instant.now();
@Embedded
private MyUserDetails details = new MyUserDetails();
private double creditBalance = 0;
@OneToMany(mappedBy = "myUser", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<Circuit> circuitList = new ArrayList<>();
public void addCircuit(Circuit circuit) {
this.circuitList.add(circuit);
circuit.setMyUser(this);
}
public void removeCircuit(Circuit circuit) {
this.circuitList.remove(circuit);
circuit.setMyUser(null);
}
@Override
public String toString() {
return email;
}
}
Цепь:
@Entity
@Data
public class Circuit {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@NotBlank
private String circuitID;
@NotBlank
private String name;
@NotNull
@Enumerated(EnumType.STRING)
private ContinentCode continentCode;
@Enumerated(EnumType.STRING)
private CountryCode countryCode;
@NotNull
private boolean enabled;
private boolean hasOnlyIPAclAccess;
@ElementCollection
private List<String> ipACL;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "fk_my_user")
private MyUser myUser;
public Circuit() {
circuitID = generateCircuitID();
name = circuitID;
enabled = true;
hasOnlyIPAclAccess = true;
ipACL = new ArrayList<>();
}
private static String generateCircuitID() {
return RandomStringUtils.randomAlphanumeric(15);
}
@Override
public int hashCode() {
return this.circuitID.hashCode();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || obj.getClass() != this.getClass())
return false;
Circuit circuit = (Circuit) obj;
return circuit.getCircuitID().equals(this.circuitID);
}
}
Это заметно, когда я впервые создаю пользователя, дочерний элемент (Цепь) еще несоздано.Это может быть создано намного позже.В чем причина этой ошибки и как ее устранить?
Любая помощь приветствуется.