jubi
jubi

Reputation: 485

Debugging JUnit Tests in a Hibernate driven Spring Application

Maybe this has been answered already, but i did not find any suggestions out there... My Project is a Spring Utility Project, the database i use is MySQL and for persistence i´m using Hibernate in combination with c3p0 connection pooling. i´m on spring 3.2 and hibernate 3.5. So here is what i want to do: I want to debug a JUnit test, step over some persistence functions (save, update, etc. ) and then check the entries manually in the database via SQL. Because of the JUnit tests always running in a transaction, i cannot check the entries in the database, because a rollback happens every time a test finished / a commit never occurs.

Is there a way to fake transaction existence, or bypassing them during JUnit tests?

Upvotes: 2

Views: 697

Answers (2)

Kkkev
Kkkev

Reputation: 4935

Rather than fake transaction existence, the best approach to looking at the database while the transaction is taking place is to query with an isolation level that allows dirty reads. The mechanism for doing this varies from database to database, and in MySQL you can use

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

prior to querying.

Clearly you will also need to force Hibernate to flush writes to the database during your test, and set your breakpoint after the flush.

Upvotes: 1

duffymo
duffymo

Reputation: 309028

Perhaps you can flush the transaction in Hibernate during your debugging session and force Spring/Hibernate to write to the database.

Or you can turn off transactions for your debugging session.

Upvotes: 2

Related Questions