У меня есть такая модель ниже: < /p>
@Entity(name = "request")
public class VisitRequest {
@Id
@GeneratedValue
private Long id;
@OneToMany(mappedBy = "visitRequest", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonManagedReference
private List visitors;
//default constructor, getters and setters
}
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "class")
public class Visitor {
@Id
@GeneratedValue
private Long id;
@ManyToOne
@JsonBackReference
private VisitRequest visitRequest;
//default constructor, getters and setters
}
@Entity
public class ContactPerson extends Visitor {
private PhoneNumber phoneNumber;
//default constructor, getters and setters
}
< /code>
Но когда я пытаюсь обновить визит, обмениваясь одним из посетителей с контактным лицом, и попытаться выполнить метод в репозитории CRUD Visitrequestrepository.save (ViteRequest); Я получаю это исключение: < /p>
servlet.service () для сервлета Вложенное исключение -
org.springframework.orm.objectretrievalfailureexception: Object
[id = null] не был из указанного подкласса
[cern.ais.visits.core.domain.visitor.visitor]: класс данного объекта
не совпадал с классом Persistend Persisted Cepy; nested exception is
org.hibernate.WrongClassException: Object [id=null] was not of the
specified subclass [cern.ais.visits.core.domain.visitor.Visitor] :
class of the given object did not match class of persistent copy] with
root cause
Может быть, проблема в том, что в базе данных есть тот же идентификатор, который используется в таблицах контакта_Перса и посетителей? < /p>
Как я могу решить проблему? Я искал решения, но никто для меня не работал.
Подробнее здесь: https://stackoverflow.com/questions/438 ... d-subclass