save method - doesn't flush the Session after an exception occurs

后端 未结 3 471
春和景丽
春和景丽 2020-12-15 22:43
public class SoftwareTest extends UnitTest {

    @Before
    public void setup() {
        Fixtures.deleteAll(); // will fail if comment that. why?????
    }

    @         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 23:07

    the issue seems to be that Hibernate raises an exception (so the current transaction gets invalidated) but then you are trying to proceed with more operations in that session.

    The proper way to do this would be to split the test you are using in 2, one part to test null authors and one to test with a valid author.

    On production code (let's say a controller), you would need to restart the operation (close the transaction, relaunch the process) to be able to proceed. But given the way play manages transactions, the normal behavior would be that after the error you would just return with an error message to the user.

提交回复
热议问题