0 Replies Latest reply on Sep 26, 2007 5:42 AM by Thomas Hamacher

    Cleaning database through hibernate

    Thomas Hamacher Novice

      Hi,

      is there a good way to clean the whole database through hibernate?

      The background is as follows: I want to clean the database every time before starting a new testcase, to make sure the database is empty and in a defined state. Currently I´m doing this through dropping the scheme and restarting the session, but this takes very long. Therefor a CREATE-DROP in the hibernate-configuratoin would not be very suitable as well, as I want to prevent hibernate from doing the mapping everytime.

      I tried doing it through the Criteria-API, fetching all java.lang.Objects and performing a session.delete(object) on every object, but this leads to a not-null or transient object exception, although I did it in one transaction with setting the flushMode to "commit".
      The other way I tried was doing this through HQL, but this leads to the problem, that I´m working with @CollectionOfElements which I cannot reference through hql (or at least I haven´t found a way to do it), but the HQL does explicitly no cascades.

      Any help would be greatly appriciated.

      Thomas