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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:43:06+00:00 2026-05-23T20:43:06+00:00

In a Spring-enabled integration test, I need to force the EntityManager to re-read from

  • 0

In a Spring-enabled integration test, I need to force the EntityManager to re-read from the database.

@Test
@DataSet("/xml/dbunit/truncate-tables.xml")
public void createTerminalFromQuery() {

    // there should be zero terminals in the empty database
    Assert.assertEquals(0, terminalService.countTerminals());

    // makes remote REST call updating database outside the application's EntityManager
    HttpEntity<QueryResponse> result = simulateRequest("query");

    // attempts to force re-read of updated database (unsuccessfully)
    entityManagerService.getEntityManager().flush();

    // there should be exactly one Terminal in the database
    Assert.assertTrue(terminalService.existsTerminalBySerialNumber(EXISTING_TERMINAL_SERIAL_NUMBER));

}

It has been verified that the Terminal is created and exists in the database. Despite this, the second assertion fails. When the first assertion is commented out, the second one is OK.

The test framework is Unitils/DBUnit and injecting an EntityManager via @PersistenceContext is difficult, as the required package unitils-orm depends on Spring 2.5 and JPA 1.0 leading to other problems.

Instead, I have created the EntityManagerService and verified that it indeed uses the same EntityManager as the TerminalService.

I have tried EntityManager.clear() and flush() and evicting the Cache from the EntityManagerFactory – but nothing seems to have any effect.

Any suggestions?

  • 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-23T20:43:07+00:00Added an answer on May 23, 2026 at 8:43 pm

    It’s not clear how do you manage transactions. Since clear() doesn’t help, perhaps both checks are executed inside the same transaction that doesn’t see result of the transaction committed by the REST service.

    Try to execute checks in different transactions.

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

Sidebar

Related Questions

Spring.NET 1.2.0 M1 comes with several XSD files for the <objects> node, database stuff,
Spring: In my context.xml, I have: <util:set id=someIDs set-class=java.util.HashSet value-type=java.lang.String> <value>W000000001</value> <value>W000000003</value> <value>W000000009</value> </util:set>
In spring you can initialize a bean by having the applicationContext.xml invoke a constructor,
I am using MyBatis with Spring Integration as described here . I am further
I have the Spring STS plugin activated within my Eclipse project. Doing this enabled
I installed Spring Security Plugin( from here ). I followed the blog post very
I have a spring application that has configured log4j (via xml) and that runs
I'm using spring based validation in combination with hibernate validator enabled by the following
I am new to Spring and Spring Security. I just need a pointer in
I'm using Spring 3.0.3. I've enabled the default ConversionService by adding this line to

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.