简体   繁体   中英

How to avoid conflict with ids inserted by DbUnit and entities inserted by Hibernate

I want to use DbUnit to test JPA/Hibernate Dao, but since DbUnit XML files contain hard-coded ids for my entities, i have problems when testing inserts done by Hibernate.

Do you know any DbUnit extension or solution which would use the PK Generator defined on my entities when inserting data from XML files ? or even insert Data with Hibernate itself ?

other strategies ?

rgds

For your hardcoded Ids in the test data you can either use negative Ids, or very high Ids, for example counting down from Integer.MAX_VALUE .

You could also use a custom Id generator. However this would require replacing the annotation for entities under test on build. You can find more details here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM