spring-boot - 使用 @Cacheable 时出现 EntityNotFoundException
问题描述
在我的应用程序中,我有多个实体,例如:
@Entity
@Data
@Builder
@ToString(of = {"id", "code", "nameContentType", "observations"})
@EqualsAndHashCode(exclude = "room")
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "desk")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Desk implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@Column(name = "code")
private String code;
@Lob
@Column(name = "name")
private byte[] name;
@Column(name = "name_content_type")
private String nameContentType;
@Column(name = "observations")
private String observations;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(unique = true)
private Coordinates coordinates;
@OneToMany(mappedBy = "desk")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private Set<Reservation> reservations = new HashSet<>();
@ManyToOne
@JoinColumn(name = "room_id", insertable = false, updatable = false)
@JsonIgnoreProperties(value = "desks", allowSetters = true)
private Room room;
}
用集合表示的所有关系都用 缓存@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
。
当我删除一些相关实体的记录时,我得到:
javax.persistence.EntityNotFoundException: Unable to find com.**.domain.Reservation with id ***
我不知道是否需要对缓存设置进行任何额外调整或如何调试问题
解决方案
你确定你更新了 Hibernate 到最新版本 5.4.32.Final 吗?如果是这样,并且您仍然有问题,请在问题跟踪器(https://hibernate.atlassian.net)中创建一个带有测试用例( https://github.com/hibernate/hibernate-test-case- )的问题重现问题的模板/blob/master/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java)。
推荐阅读
- javascript - 即使在添加 CORSMiddleware 之后也会出现 CORS 错误
- python - ARM 上的顽固 numpy 错误 - 有或没有 venv - 无法回滚 numpy;未卸载
- r - R包amt:如何为不同的个体计算不同数量的随机位置
- python - 如何将变量传递给 os.popen?
- javascript - querySelector 如何处理动态创建的元素
- r - 根据 R 中的数字模式创建新变量
- c# - 如何使用 Azure IoT 查找地图路线?
- javascript - 在 ReactJS 中使用箭头函数或 onClick 函数之间的区别?
- html - 如何在 CSS 中使边框伸展到其父级的全高?
- java - Java MouseEvent 和运行循环