如何删除所有JPA实体? [英] How do I delete all JPA entities?
本文介绍了如何删除所有JPA实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的测试代码中,每种方法都需要有一个空白/空数据库.有没有可以实现此目的的代码,可以调用测试的@Before?
In my testing code I need to have a blank/empty database at each method. Is there code that would achieve that, to call in the @Before of the test?
推荐答案
实际上,您始终可以使用JPQL,
Actually you always can use JPQL,
em
.createQuery("DELETE FROM MyEntity m")
.executeUpdate()
;
但是请注意,没有授予实体缓存也将被清除的授权.但是出于单元测试的目的,这似乎是一个很好的解决方案.
But note, there is no grants that entity cache would be cleaned also. But for unit-test purposes it is look like good solution.
这篇关于如何删除所有JPA实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文