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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:47:00+00:00 2026-06-14T16:47:00+00:00

I have been annoyed and bothered by this problem for a while and finally

  • 0

I have been annoyed and bothered by this problem for a while and finally worked up an example to show what is happening. Hopefully somebody else has the slightest clue what is going on.

I have a Spring Transactional JUnit test with @Rollback(true). The test is wrapped in a HibernateTransaction that rollsback the database changes at the end of the unit test automatically. This appears to be working, however in this bizarre scenario with this one query and only in my unit tests will this one @Transactional Business Logic method return null.

@Test
@Rollback(true)
public void testObscureIssue() throws Exception {
    // Not important...
    l = createLeague();
    t1 = createTeam(l);
    User u = userBo.getUser(1L, false);

    Player player = TestUtils.getInstance().createTestData(Player.class, 1).get(0);
    player.setUser(u);
    player.setGender("M");
    player.setStartingActivityLevel(ActivityLevelEnum.Sedentary);
    playerBo.addOrUpdate(player);
    TeamPlayer tp = new TeamPlayer(t1, player);
    leagueStructureBo.addOrUpdate(tp);

    // This test will pass 10% of the time, seemingly random. Randomness only inside of unit test
    Team t = playerBo.getCurrentTeam(player.getPlayerID());
    if (t == null) throw new OutOfMemoryError("What is this... I don't even...");

    Team expected = playerBo.getCurrentTeam(player.getPlayerID());
    assertNotNull(expected);
    assertEquals(t1, expected);
}

So the method playerBo.getCurrentTeam always returns correctly in the application, and always returns correctly if I place a breakpoint anywhere in the unit test then step through the code one line at a time. It will most of the time fail however when simply running the unit test without debugging.

I thought perhaps there is some racing condition occurring here, but even if I put a Thread.sleep(400000L); statement before calling this Transactional method it will still fail.

Code for the transactional method:

@Override
@Transactional
public Team getCurrentTeam(long playerId) {
    String qry = "select t from Team as t inner join t.teamPlayers as tp " +
            "inner join tp.player as tpp where tpp.playerID = :playerId and (((current_timestamp() between tp.startDate and tp.endDate " +
            "and tp.endDate is not null) or (tp.endDate is null and current_timestamp() > tp.startDate)))";
    Object wtf = sessionFactory.getCurrentSession().createQuery(qry)
            .setParameter("playerId", new Long(playerId)).uniqueResult();
    return (Team)wtf;
}

The Transaction attributes are all default for a Spring Hibernate4 TransactionManager.

You can see in the code example that I have clearly created this Team entity and the log shows the generated ID for the new record. I can query the record directly by that ID using HQL and it WILL return, but then this one HQL query above in this Transactional method still will return null unless I step through it in debug mode, then it works.

Is this a problem with nested transactions because I was under the impression that nothing gets rolled back until the outermost transaction is rolledback. Why only on this one particular method? Is it a bug with Hibernate 4 or Spring 3.1.1? I am using MySQL InnoDB, could this be an issue with the way that MySQL InnoDB handles database transactions?

Any suggestions of additional things to try are welcome because I am completely out of ideas here.

  • 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-14T16:47:01+00:00Added an answer on June 14, 2026 at 4:47 pm

    My guess is that the problem comes from the use of current_timestamp(). You probably created the TeamPlayer with now as the start date, and if you put a breakpoint, the current timestamp is systematically begger than the start date, whereas if you don’t put a breakpoint, the code is fast enough, 10% of the time, to have a the current timestamp equal to the start date of the team player.

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

Sidebar

Related Questions

I've been searching for a problem that have annoyed me for a while (but
I have never been so annoyed with this wpf toolkit. The documentation is just
Have been trying to fix this problem I have here. Basically I have a
Have been struggling all day trying to make this simple example work using socket.io.
Have been stuck on this (beginner) issue for a while so am now asking
Introduction I have been so annoyed by applications that have a startup dialog which
Have been working on this question for a couple hours and have come close
I have been working with SQL Server as a Developer a while. One thing
I've been annoyed by this for a long time now. Somehow Visual Studio 2010
have been working and wearing out my fingers doing google searches with this one:

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.