-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate - JUnit - SchemaExport
PostPosted: Mon May 03, 2010 4:43 pm 
Newbie

Joined: Fri Jan 29, 2010 8:37 am
Posts: 5
Hi,
I'm writing some integrations tests in JUnit. What happens here is that when i run all the tests together in a row (and not separately), the data persisted in the database always changes and the tests find unexpected data (inserted by the previous test) during their execution.

So I created a @Before method in my base test class to drop and create the schema between each execution (it's slow, but it should work):

Code:
   @Before
   public void before() {
      Configuration configuration = new Configuration().configure();
      SessionFactory sessionFactory =configuration.buildSessionFactory();
      Session session = sessionFactory.openSession();
      Connection connection = session.connection();
      SchemaExport schemaExport = new SchemaExport(configuration, connection);
      schemaExport.execute(false, true, true, true);
      session.close();
   }


But unfortunately it doesn't seem to work. The problem here is that i also need the auto-increment columns to be reset, because in my tests i check the IDs of the persisted entities, so that i thought that a drop and create operation would regenerate the columns and, by doing so, reset the auto-increment column of each table between each test execution.

Any tips?
Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.