Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4030050
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:25:22+00:00 2026-05-20T11:25:22+00:00

I have just set up a test that checks that I am able to

  • 0

I have just set up a test that checks that I am able to insert entries into my database using Hibernate. The thing that drives me crazy is that Hibernate does not actually delete the entries, although it reports that they are gone!

The test below runs successfully, but when I check my DB afterwards the entries that were inserted are still there! I even try to check it using assert (yes I have -ea as vm parameter). Does anyone have a clue why the entries are not deleted?

public class HibernateExportStatisticDaoIntegrationTest {
    HibernateExportStatisticDao dao;
    Transaction transaction;

    @Before
    public void setUp(){
        assert numberOfStatisticRowsInDB() == 0;
        dao = new HibernateExportStatisticDao(HibernateUtil.getSessionFactory());
    }

    @After
    public void deleteAllEntries(){
        assert numberOfStatisticRowsInDB() != 0;
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        for(PersistableStatisticItem item:allStatisticItemsInDB()) {
            session.delete(item);
        }
        session.flush();
        assert numberOfStatisticRowsInDB() == 0;
    }

    @Test public void exportAllSavesEntriesToDatabase(){
        int expectedNumberOfStatistics = 20;
        dao.exportAll(StatisticItemFactory.createTestStatistics(expectedNumberOfStatistics));

        assertEquals(expectedNumberOfStatistics, numberOfStatisticRowsInDB());
    }

    private int numberOfStatisticRowsInDB() {
        return allStatisticItemsInDB().size();
    }

    @SuppressWarnings("unchecked")
    private List<PersistableStatisticItem> allStatisticItemsInDB(){
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        transaction = session.beginTransaction();
        Query q = session.createQuery("FROM PersistableStatisticItem item");
        return q.list();
    }
}

The console is filled with

Hibernate: delete from UPTIME_STATISTICS where logDate=? and serviceId=?

but nothing has been deleted when I check it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:25:22+00:00Added an answer on May 20, 2026 at 11:25 am

    I guess it’s related to inconsistent use of transactions (note that beginTransaction() in allStatisticItemsInDB() is called several times without corresponding commits).

    Try to manage transactions in proper way, for example, like this:

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction tx = session.beginTransaction();
    for(PersistableStatisticItem item:
        session.createQuery("FROM PersistableStatisticItem item").list()) {
        session.delete(item);
    }
    session.flush();
    assert session.createQuery("FROM PersistableStatisticItem item").list().size() == 0;
    tx.commit();
    

    See also:

    • 13.2. Database transaction demarcation
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MoQ to test some controllers I have. I'm not able to set
I have just set up cruise control.net on our build server, and I am
I have a WPF app which snaps to screen edges (I just set the
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have just inherited a server application, however it seems that the only copy
I have just got a MacBook Pro and have been using it (+Fusion) to
I have just started using silverlight 2 beta and cannot find how to or
I have just started using Boost 1.36. These libraries would be very useful in
I have a test setup where I have many very similar unit tests that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.