0

I have test:

    @Transactional(propagation=Propagation.REQUIRES_NEW)
    @Test
    @ExpectedDatabase(
            value = "classpath:ExpectedAddedDonation.xml",
            assertionMode = DatabaseAssertionMode.NON_STRICT
            )
    public void testAddDonations() throws MalformedURLException, SQLException, DatabaseUnitException {
        prepareCategoriesAndProjects();
        Project proj = (Project) session.get(Project.class, 1);
        Project proj2 = (Project) session.get(Project.class, 2);
        DonationLogic donation = new DonationLogic(10000,50);
        donation.setProject(proj);
        DonationLogic donation2 = new DonationLogic(100000,500);
        donation2.setProject(proj2);

        System.out.println(donation.getProject().getName() + "---" + donation.getCollectAmount() + "---" + donation.getDaysLeft() + "---" + donation.getTotalAmount());
//      session.flush();
        session.persist(donation);
        session.persist(donation2);

    }

    private void prepareCategoriesAndProjects() throws MalformedURLException, DataSetException, SQLException, DatabaseUnitException {
        IDataSet dataSet = new FlatXmlDataSetBuilder().build(new File(
                "./src/test/resources/sampleDataForShow.xml"
                ));
        IDatabaseConnection dbConn = new DatabaseDataSourceConnection(dataSource);
        DatabaseOperation.CLEAN_INSERT.execute(dbConn, dataSet);
    }

Test checks if two rows are added to donations table. Test is successful only when I change persist() to save(). And I dont understand why persist() does not work? Hibernate does not generate INSERT queries.

ovod
  • 1,118
  • 4
  • 18
  • 33

1 Answers1

0

You are guaranteed that queries will be issued after flush operation. All the other things can be postponed. The same with save actually. Here can be found a bit more info.

Community
  • 1
  • 1
asm0dey
  • 2,841
  • 2
  • 20
  • 33