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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:39:26+00:00 2026-06-03T05:39:26+00:00

I just started out writing my first unit tests with JUnit and I ran

  • 0

I just started out writing my first unit tests with JUnit and I ran into a small problem.
Inside my unit-tests i’m inserting new data into my MySql database. After I added my info, I delete that same info in the next unit test.

My table-id is auto-incrementing and with each unit-test I run the value for the next id is incremented with 1.

I implemented a new method with the @AfterClass annotation so that after I’m done with my unit-tests it will reset the increment value. I used this query:

entityManager.createNativeQuery("ALTER TABLE student AUTO_INCREMENT = 1");

If I add new info directly into my MySql database the value of the next id isn’t what I want it to be (last id value in my table +1).

However when I run the sql-query directly in the database, the query does work.

My question: Is it impossible to run these kind of queries while unit-testing? Or am I totally looking at this the wrong way.

I’m using java, spring, hibernate, jpa , junit

Thanks in advance!

  • 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-06-03T05:39:27+00:00Added an answer on June 3, 2026 at 5:39 am

    You created a query, but forgot to execute it:

    entityManager
        .createNativeQuery("ALTER TABLE student AUTO_INCREMENT = 1")
        .executeUpdate(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to C and have started out writing a small library with
I just started out with a new site and I decided to use DOMImplementation
I'm just starting to learn Android development and writing my first app. I started
I just started out with C and have very little knowledge about performance issues
I just started out using wordpress as a CMS. On the site I have
I just started out with RequireJS, but i'm stuck at the part where i
We have just started out with Team Foundation Server 2008 / Visual Studio Team
I have just started out with testing some php mvc framework In it, it
I've just started building a prototype application in Django. I started out by working
I have just started learning Erlang and am trying out some Project Euler problems

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.