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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:57:38+00:00 2026-05-16T03:57:38+00:00

I have a JUnit 4 test case with the Spring @Transactional annotation that saves

  • 0

I have a JUnit 4 test case with the Spring @Transactional annotation that saves an object, and then attempts to find it. The test case passes when I use this implementation:

@Override
public EventSummary findEventSummaryById(Integer id) {
    return em.find(EventSummary.class, id);
}

It fails when I use this implementation (and then change which method I call in the test case):

@Override
public EventSummary findEventSummary(Integer id) {
    Query query = em.createQuery("select es from EventSummary as es where es.id = :id");
    query.setParameter("id", id);
    EventSummary result = (EventSummary) query.getSingleResult();
    return result;
}
  • 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-16T03:57:39+00:00Added an answer on May 16, 2026 at 3:57 am

    If you are using the default flush mode (AUTO) and if you are executing your query within a transaction, the JPA specification guarantees that a Query will not return stale or incorrect data:

    3.6.2 Queries and FlushMode

    The flush mode setting affects the
    result of a query as follows.

    When queries are executed within a
    transaction, if FlushModeType.AUTO
    is set on the Query object, or if the
    flush mode setting for the persistence
    context is AUTO (the default) and a
    flush mode setting has not been
    specified for the Query object, the
    persistence provider is responsible
    for ensuring that all updates to the
    state of all entities in the
    persistence context which could
    potentially affect the result of the
    query are visible to the processing of
    the query. The persistence provider
    implementation may achieve this by
    flushing those entities to the
    database or by some other means. If
    FlushModeType.COMMIT is set, the
    effect of updates made to entities in
    the persistence context upon queries
    is unspecified.

    public enum FlushModeType {
        COMMIT,
        AUTO
    }
    

    If there is no transaction active, the
    persistence provider must not flush to
    the database.

    Assuming that you are using AUTO, check the transactional side.

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

Sidebar

Related Questions

I have a JUnit test that tests adding Strings to a Dictionary custom type.
I have a JUnit test that is checking to make sure that a customized
I have an extremely odd problem in my JUnit tests that I just can't
I have a JUnit 3.x TestCase which I would like to be able to
I would like to use two different implementations for a DAO with Spring's testframework.
We have a Spring + Ibatis based J2EE app. I planned to wrap around
I have a Web application using spring and hibernate and struts (it runs on
I am working on a Java application that will use some Hibernate (annotated by
I have a method that is going to the DB so all our JDBC
Have just started using Google Chrome , and noticed in parts of our site,

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.