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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:50:08+00:00 2026-05-13T21:50:08+00:00

I’m trying to set up integration tests using the AbstractTransactionalJUnit4SpringContextTests base class. My goal

  • 0

I’m trying to set up integration tests using the AbstractTransactionalJUnit4SpringContextTests base class. My goal is really simple: insert some data into the database using the simpleJdbcTemplate, read it back out using a DAO, and roll everything back. JPA->Hibernate is the persistence layer.

For my tests, I’ve created a version of the database that has no foreign keys. This should speed up testing by reducing the amount of fixture setup for each test; at this stage I’m not interested in testing the DB integrity, just the business logic in my HQL.

/* DAO */

@Transactional
@Repository("gearDao")
public class GearDaoImpl implements GearDao {
    @PersistenceContext
    private EntityManager entityManager;

    /* Properties go here */

    public Gear findById(Long id) {
        return entityManager.find(Gear.class, id);
    }
}

/* Test Page */

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/com/dom/app/dao/DaoTests-context.xml"})
@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=false)
public class GearDaoImplTests extends AbstractTransactionalJUnit4SpringContextTests   {

    @Autowired
    private GearDao gearDao;

    @Test
    @Rollback(true)
    public void quickTest() {
        String sql;
        // fields renamed to protect the innocent :-)
        sql = "INSERT INTO Gear (Gear_Id, fld2, fld3, fld4, fld5, fld6, fld7) " +
              " VALUES (?,?,?,?,?,?,?)";
        simpleJdbcTemplate.update(sql, 1L, 1L, 1L, "fld4", "fld5", new Date(), "fld7");
        assertEquals(1L, simpleJdbcTemplate.queryForLong("select Gear_Id from Gear where Gear_Id = 1"));
        System.out.println(gearDao);

        Gear gear = gearDao.findById(1L);
        assertNotNull("gear is null.", gear);  // <== This fails.
    }
}

The application (a Spring MVC site) works fine with the DAO’s. What could be happening? And where would I begin to look for a solution?

  1. The DAO somehow has a different dataSource than the simpleJdbcTemplate. Not sure how this would be, though, since there’s only one dataSource defined in the DaoTests-context.xml file.
  2. Hibernate requires all foreign key relations to be present in order to select out the Gear object. There are a couple of joins that are not present since I’m hardcoding those in fld2/fld3/fld4.
  3. The DAO won’t act on the uncommitted data. But why would the simpleJdbcTemplate honor this? I’d assume they both do the same thing.
  4. Underpants gnomes. But where’s the profit?
  • 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-13T21:50:09+00:00Added an answer on May 13, 2026 at 9:50 pm

    What a difference a couple hours of sleep makes. I woke up and thought “I should check the logs to see what query is actually being executed.” And of course it turns out that hibernate was configured to generate some inner joins for a few of the foreign keys. Once I supplied those dependencies it worked like a charm.

    I’m loving the automatic rollback on every test concept. Integration tests, here I come!

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

Sidebar

Ask A Question

Stats

  • Questions 380k
  • Answers 380k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer ... $url = 'http://www.domain.com/something/interesting_part/?somevars&othervars'; $parts = explode('/', $url); echo $parts[4];… May 14, 2026 at 9:49 pm
  • Editorial Team
    Editorial Team added an answer preg_match_all('/\[\d+,\d+\]/', $inp1, $matches); $result = implode(' ', $matches[0]); May 14, 2026 at 9:49 pm
  • Editorial Team
    Editorial Team added an answer Make sure you have a reference to the System.Windows.Controls.Toolkit assembly.… May 14, 2026 at 9:49 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.