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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:53:59+00:00 2026-05-31T22:53:59+00:00

Have a JUNIT test set up as such @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ /applicationContext.xml, /applicationContext-security.xml }) @TransactionConfiguration(defaultRollback

  • 0

Have a JUNIT test set up as such

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "/applicationContext.xml", "/applicationContext-security.xml" })
@TransactionConfiguration(defaultRollback = true)
@Transactional
public class BlahIntegrationTests{

 @Test
 public void testMappingsOfHugeObjectGraph(){
 }
}

I’m attempting to test that my hibernate mappings (annotation driven and JPA based) are correct and when run like above my test passes (just asserts that an ID is created).

If I take the @Transactional away, I get errors with some of my relationships which I was expecting. Anyone have thoughts on why it’s not failing when it’s @Transactional?

EDIT: To Clarify, the exception that was thrown was regarding bad hibernate mappings (it’s a very large object structure and I had borked some of them) upon saving of the object

  • 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-31T22:54:00+00:00Added an answer on May 31, 2026 at 10:54 pm

    If you remove @Transactional your test DB won’t be empty for another test and therefore tests won’t be isolated.

    If you have it there then some tests may pass even though they should fail (as you described, or another example is if you insert entity wich duplicates some unique constraint).

    Solution is to have @Transactional in its place and inject

    @PersistenceContext
    private EntityManager em;
    

    and do following before you extract your data from database

    em.flush();
    em.clear();
    

    The first line will cause synchronization between session and database (your provider usually waits till the end of the transaction).
    The second line will remove all entities from session so all queries will go to the database.

    And after the test everything is still rolled back so you have your database in original state.

    Hope it helps.

    • 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 suite in the form: @RunWith(Suite.class) @Suite.SuiteClasses( { xx.class, yy.cass
I have this JUnit test that I need help developing a Interface and Class
I have a JUnit test class in which I have several static final int
I have a Spring JUnit test with configuration files and @ContextConfiguration parameters: package ru.csbi.registry.domain.envers.integration;
I am fairly new to Java. I have constructed a single JUnit test class
I have a simple test set up in JUnit, along the lines of public
I have list of items like this: <ItemGroup> <ToCompile Include=clojure\core.clj;clojure\set.clj;clojure\zip.clj;clojure\test\junit.clj;/> </ItemGroup> And I want
I have a JUnit test that tests adding Strings to a Dictionary custom type.
I have a JUnit test that fails because the milliseconds are different. In this
Normally I would have one junit test that shows up in my integration server

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.