could not execute statement [Cannot add or update a child row: a foreign key constraint fails (demodbdev.entityimage, CONSTRAINT FKcdf6ngpc2Sr30p4V53v28obay FOREIGN KEY (item_id) REFERENCES enitiyitemtwo (id))][update entityimage set item_id=? where image_id=?]; SQL [update entityimage set item_id=? where image_id=?]; constraint [null]]
Execution: Trying to save the EnitiyItemOne entity using EnitiyItemOne repo but in the above exception autogenerated query is showing 'REFERENCES enitiyitemtwo (id))', here referencing the wrong table enitiyitemtwo, it should be enitiyitemone table as I am trying to save the EnitiyItemOne entity.
public class EntityImage{
@Id
private long image_id;
private String image_path;
private long item_id;
}
public class EnitiyItemOne{
@Id
private long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "item_id")
private List itemImages;
}
public class EnitiyItemTwo{
@Id
private long id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "item_id")
private List itemImages;
}
Примечание: item_id — это внешний ключ, используемый в таблице EntityImage.
Возможна ли указанная выше структура в Springboot с использованием базы данных MYSQL?< /п>
Исключение: [code]could not execute statement [Cannot add or update a child row: a foreign key constraint fails (demodbdev.entityimage, CONSTRAINT FKcdf6ngpc2Sr30p4V53v28obay FOREIGN KEY (item_id) REFERENCES enitiyitemtwo (id))][update entityimage set item_id=? where image_id=?]; SQL [update entityimage set item_id=? where image_id=?]; constraint [null]]
Execution: Trying to save the EnitiyItemOne entity using EnitiyItemOne repo but in the above exception autogenerated query is showing 'REFERENCES enitiyitemtwo (id))', here referencing the wrong table enitiyitemtwo, it should be enitiyitemone table as I am trying to save the EnitiyItemOne entity. [/code] Сценарий: [code]public class EntityImage{ @Id private long image_id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "item_id") private List itemImages; } [/code] Примечание: item_id — это внешний ключ, используемый в таблице EntityImage. Возможна ли указанная выше структура в Springboot с использованием базы данных MYSQL?< /п>
В Spring Boot и Java 8 имеется несколько моделей: DTO, Entities, ViewModels и т. д., но необходимо получить и сохранить описание человека, но в описании необходимо обрезать значение, например:
@Size(min=0, max=1024)
private String description;...
@Entity Пользователь { @ManyToOne(mappedBy = пользователь ) Список комментариев; } @Сущность Комментарий { @ManyToOne Пользователь Пользователь; } Есть ли способ добавить метод с некоторыми условиями для...