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?
相关问题
- How does the JPA handle partial, non-disjoint inhe
- JPA and eclipselink - Overriding FetchType.Eager
- JPQL we can't CONCAT(String, Integer) EclipseL
- Get last record from @OneToMany relationship
- eclipselink + @convert(json) + postgres + list pro
相关文章
- how to set H2 primary key id to auto_increment?
- JPA cascade persist - many to one
- How to apply Static Weaving Ant Task with Eclipse-
- Test the error code of a custom exception with JUn
- JUnit4 and JUnit5 tests not running in IntelliJ
- How to stop LocalDate from changing when being sav
- Will the 'finally' block fire even after a
- JPA lazy loading Collections in JSF view - better
Actually you always can use JPQL,
But note, there is no grants that entity cache would be cleaned also. But for unit-test purposes it is look like good solution.
I would run the test methods insider a transaction (and rollback at the end of each method). That's the usual approach. I don't see the point of committing a transaction and writing data to the database if you DELETE them just after. Just don't commit.
An alternative (not exclusive) would be to use DbUnit to put your database in a known state before a test execution. When doing this, you usually don't need to clean it up.
Another option would be to use raw JDBC to drop the database if exists and then have JPA recreate the whole database. Will be pretty slow though.