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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:25:09+00:00 2026-05-15T17:25:09+00:00

I am using Hibernate / Spring / Maven / MySQL and unit tests with

  • 0

I am using Hibernate / Spring / Maven / MySQL and unit tests with JUnit. Up to yesterday, my testdata persisted in the database even after the test run was completed. I configured the hell out of this day and all of the sudden all data are being deleted after every test run. Quite sure, this is no bug, but a config issue. Nevertheless, I am lost.

appContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util">

      <tx:annotation-driven/>
    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>

    <bean class="org.springbyexample.util.log.AnnotationLoggerBeanPostProcessor" />

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>classpath:/settings.properties</value>
        </property>
    </bean>

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${driver}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${user}"/>
        <property name="password" value="${password}"/>
    </bean>

       <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceUnitName" value="RDBMS"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="generateDdl" value="false"/>
                <property name="showSql" value="true"/>
                <property name="databasePlatform" value="${databasePlatformDialect}"/>
                <property name="database">
                    <util:constant static-field="${databaseVendor}" />
                </property>
            </bean>
        </property>    
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <context:component-scan base-package="de.test">
         <context:exclude-filter type="regex" expression="de\.sandbox\.test\.hibernatedao.*"/>
    </context:component-scan>

    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    </beans>

persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">

    <persistence-unit name="RDBMS" transaction-type="RESOURCE_LOCAL">
        <exclude-unlisted-classes>true</exclude-unlisted-classes> 
    </persistence-unit>
</persistence>

Thanks for suggestions.

EDIT —-
As demanded, the testcase:

package de.test.base;

import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/appContextMain.xml")
@Transactional
public abstract class SpringTestCase {
}

Child:

package de.test.dao;

import de.test.base.SpringTestCase;
import de.test.businessobjects.BodSt;
import de.test.businessobjects.Trainee;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.springbyexample.util.log.AutowiredLogger;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collection;
import java.util.List;

public class BodStDAOTest extends SpringTestCase {

    @AutowiredLogger
    final Logger logger = null;

    @Autowired
    private IBodStDAO bodStDAO;

    @Autowired
    private ITraineeDAO traineeDAO;

    Trainee trainee = new Trainee();

    @Before
    public void onSetUpInTransaction() throws Exception {

        this.trainee.setName("Name");
        this.trainee.setSurname("Surname");
        this.trainee = this.traineeDAO.save(this.trainee);
    }

    @Test
    public void testSingleObjectSave() throws Exception {

        Collection before = (List) this.bodStDAO.getAll();

        BodSt bodSt = new BodSt();
        bodSt.setWeight((float) 2.2);
        bodSt.setHeight(new Float(0.0));
        bodSt.setTrainee(trainee);
        bodSt = this.bodStDAO.save(bodSt);

        Collection after = (List) this.bodStDAO.getAll();

        this.logger.info("BodSt size before: " + before.size() + " and after: " + after.size());
        Assert.assertEquals(before.size() + 1, after.size());
    }
}
  • 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-15T17:25:10+00:00Added an answer on May 15, 2026 at 5:25 pm

    Using @Rollback(value = false) annotation on your test case that creates the test data makes sure that the data doesnt get deleted.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Found a workaround here: http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/016ad28b-f813-4f26-9e70-2265a1943bad In short: the query works… May 16, 2026 at 10:04 am
  • Editorial Team
    Editorial Team added an answer RFC 3174 http://www.faqs.org/rfcs/rfc3174.html (aka SHA-1) May 16, 2026 at 10:04 am
  • Editorial Team
    Editorial Team added an answer Here’s a fairly hacky solution. Change your touchmove handler as… May 16, 2026 at 10:04 am

Trending Tags

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

Top Members

Related Questions

In my project I can successfully test database code. I'm using Spring, Hibernate, HSQLDB,
We're using Maven/Surefire and Spring/Hibernate transactional tests for a fairly large web application. There
WHen deploying my Spring / Hibernate application, I get the following warning related to
Hi I'm starting a new web development project with my team using Hibernate and
I am trying to generate struts 2 modular archetype using maven but always getting
I want to create a web app that will use wicket, hibernate and spring
i am coming back because i still have problem using JodaTime. After the previous
I am using maven2 with a struts-hibernate Java EE project and developing with myEclipse.
Our current database (MySQL) already has Indexes for its foreign keys since these use
I would like to use hibernate for persisting objects through web services and am

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.