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 7160579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:25:19+00:00 2026-05-28T13:25:19+00:00

I have around 10 JUnit that will be executed automatically. I would like to

  • 0

I have around 10 JUnit that will be executed automatically. I would like to reset the database in every of them. I have this piece of code:

//@Transactional
public class TestMediaObjectService extends AbstractDataAccessTest{

//This method reset the database, emptying the tables
    @Test
    public void testCreateDataBase() throws Exception {
        TestDatabaseCreation creation = new TestDatabaseCreation();
        creation.resetDatabase();
    }

//This is one of the methods. 
    @Test
    public void testStoreMediaObject() throws Exception {
//......
}

When I reset the database manually with the same script that I am using in the method testCreateDataBase and after that run this test (without that method), the tables are created automatically. But if I run the code as I have pasted above, that tables are not created, therefore I get this error:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘one_table’ doesn’t exist

How could I run that method in every before running other methods in the test? The annotation @Transactional was removed, but error was still there.

  • 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-28T13:25:20+00:00Added an answer on May 28, 2026 at 1:25 pm

    Usually you don’t need to reset the database manually, because JUNIT does this for you before every test. Use these annotations:

    @TransactionConfiguration(defaultRollback = true)
    @Transactional
    @RunWith(SpringJUnit4ClassRunner.class)
    

    Junit will rollback all transactions done in a test after running it. All you need is an existing empty database. If you use hibernate to manage your entities, you don’t even need to have the tables.

    If you want to do it manually, use the @Before annotation at a setup method:

    @Before
    public void init() {
        createTables();
    }
    

    This will be run before every test.

    If you want to setup your database tables once for all tests in a class, use @BeforeClass. But usually that’s not best practice, as every test should be independent of any other test.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have around 3500 flood control facilities that I would like to represent as
I have around 200 jpg images. I need to stack them so that i
We have around 100 database migration files. Many of them make schema changes which
I have around 100 locations and would like to display the last five locations
I have around 1000 pdf filesand I need to convert them to 300 dpi
I have around 400 GB Live mysql Databases on one server and I like
I have around 100 rows of text that I want to tokenize, which are
I have around 4000 entities that I need to insert into a Java App
I have a piece of code similar to the below that I have been
I have around fifty migrations in my store app, some of them are schemamigration

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.