添加子对象 JPA 后强制刷新对象父项



我在数据库中创建一个对象子级后,使用 JpaRepository。我检索了一个对象父对象,但父对象中不存在新的子对象。级联不刷新。

为了检索父对象,我使用方法findOne或getOne,但问题是相同的。我正在尝试使用,但问题是相同的:

	@Query("select u from User u where u.id=:x")
	public User findUserById(@Param("x") String id);

一个用户有一个 Profil 集合,一个用户有一个用户。有一次,我在尝试检索用户后创建了一个 Profil,但新的 profil 添加它没有在这里

In User Entity 
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL) @LazyCollection(LazyCollectionOption.FALSE) 
private Collection<Profil> profils; 
In profil entity 
@ManyToOne(cascade = CascadeType.ALL) 
private User user; 

我如何强制使用数据库中的新元素刷新 jpa?谢谢

EntityManager 接口有方法

void refresh(Object entity)

或者您可以尝试访问缓存并逐出((实体

entityManager.getEntityManagerFactory().getCache().evict(...) or evictAll();

最新更新