JPA delete remove 时 上级的Collection 不删除

JPA  delete remove 时 上级的Collection 不删除

问题 class A{

objects ...

Collection<B> collection;

}

Class B{

A a;

}

数据库B 作为A的外键 many-to-one

当删除B时,A的collection 仍然能获取到B.


解决:删除缓存

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

entityManager.getEntityManagerFactory().getCache().evict(A.class);



猜你喜欢

转载自blog.csdn.net/lvzhyt/article/details/50977188