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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:44:30+00:00 2026-06-12T15:44:30+00:00

I use Spring test DBUnit to test my DB Service and Hibernate. I wrote

  • 0

I use Spring test DBUnit to test my DB Service and Hibernate.
I wrote a simplest test possible:

@Test
    @DatabaseSetup("dumbDataSample_DBAccount.xml")
    @DatabaseTearDown("dumbDataSample_DBAccount.xml")
    @ExpectedDatabase(assertionMode=DatabaseAssertionMode.NON_STRICT, value ="dumbDataSample_DBAccount.xml")
    public void testBasic() {
    }

And it fails! Why? It did work before I modified the table (removed some fields, added other, reassigned primary key ) It seem that DBunit compares companyName columns from different records
dumbDataSample_DBAccount.xml

    <?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <adminaccounts username="naruto" forcePassChange="true" companyName="Konoha" email="naruto@konoha.jp"/>
    <adminaccounts username="sephiroth" forcePassChange="false" companyName="Shinra" email="sephi@shinra.com"/>
    <adminaccounts username="geralt" forcePassChange="false" companyName="no"/>
</dataset>

Any ideas?
Here is the trace

junit.framework.ComparisonFailure: value (table=adminaccounts, row=0, col=companyName) expected:<[Konoha]> but was:<[no]>
    at org.dbunit.assertion.JUnitFailureFactory.createFailure(JUnitFailureFactory.java:39)
    at org.dbunit.assertion.DefaultFailureHandler.createFailure(DefaultFailureHandler.java:105)
    at org.dbunit.assertion.DefaultFailureHandler.handle(DefaultFailureHandler.java:208)
    at org.dbunit.assertion.DbUnitAssert.compareData(DbUnitAssert.java:524)
    at org.dbunit.assertion.DbUnitAssert.assertEquals(DbUnitAssert.java:409)
    at org.dbunit.assertion.DbUnitAssert.assertEquals(DbUnitAssert.java:312)
    at org.dbunit.assertion.DbUnitAssert.assertEquals(DbUnitAssert.java:274)
    at org.dbunit.assertion.DbUnitAssert.assertEqualsIgnoreCols(DbUnitAssert.java:122)
    at org.dbunit.Assertion.assertEqualsIgnoreCols(Assertion.java:74)
    at com.github.springtestdbunit.assertion.NonStrictDatabaseAssertion.assertEquals(NonStrictDatabaseAssertion.java:44)
    at com.github.springtestdbunit.DbUnitRunner.verifyExpected(DbUnitRunner.java:128)
    at com.github.springtestdbunit.DbUnitRunner.afterTestMethod(DbUnitRunner.java:80)
    at com.github.springtestdbunit.DbUnitTestExecutionListener.afterTestMethod(DbUnitTestExecutionListener.java:141)
    at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:406)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:91)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)

Here is the table’s script:

CREATE TABLE `adminaccounts` (
`username` varchar(50) NOT NULL,
`companyName` varchar(50) NOT NULL DEFAULT 'Unknown',
`email` varchar(50) DEFAULT NULL,
`forcePassChange` bit(1) NOT NULL DEFAULT b'1',
PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Here is my Entity class:

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="adminaccounts")
public class DBAccount implements Serializable {
    private static final long serialVersionUID = 1L;
    /** Account name */
    @Id
    @Column(name="username")
    private String username;
    public void setUsername(String n)
    {
        this.username = n;
    }
    public String getUsername()
    {
        return this.username;
    }
    /** Force password change flag */
    @Column(name="forcePassChange")
    private boolean forceChange;
    public void setForceChange(boolean f)
    {
        this.forceChange = f;
    }
    public boolean getForceChange()
    {
        return this.forceChange;
    }
    /**  Company name */
    @Column(name="companyName")
    private String company;
    public void setCompany(String c)
    {
        this.company = c;
    }
    public String getCompany()
    {
        return this.company;
    }
    /** email */
    @Column(name="email")
    private String email;
    public void setEmail(String e)
    {
        this.email = e;
    }
    public String getEmail()
    {
        return this.email;
    }

    public String toString()
    {
        String s = this.username + " " + this.company + " " + this.email + " " + (this.forceChange ? "Force" : "No force");
        return s;
    }

}

hibernate config:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <mapping class="jp.co.rns.model.DBAccount" />
    </session-factory>

</hibernate-configuration>

I use annotations so no persistence.xml file

Here is test context

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

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />    
    <!-- ===============Properties files================== -->
 <util:properties id="appProperties" 
    location="classpath:application.properties">
    </util:properties>
 <beans:bean id="propertyConfigurer"
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
     p:location="classpath:jdbc.properties" />
<!-- ================================================= -->

     <beans:bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <beans:property name="dataSource" ref="dataSource" />
        <beans:property name="configLocation">
            <beans:value>classpath:hibernate.cfg.xml</beans:value>
        </beans:property>
        <beans:property name="configurationClass">
            <beans:value>org.hibernate.cfg.AnnotationConfiguration</beans:value>
        </beans:property>
        <beans:property name="hibernateProperties">
            <beans:props>
                <beans:prop key="hibernate.dialect">${jdbc.dialect}</beans:prop>
                <beans:prop key="hibernate.show_sql">true</beans:prop>
            </beans:props>
        </beans:property>
    </beans:bean>

    <tx:annotation-driven />
    <beans:bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <beans:property name="sessionFactory" ref="sessionFactory" />
    </beans:bean>

       <!--   p:driverClassName="${jdbc.driverClassName}"-->
    <beans:bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
        p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
        p:password="${jdbc.password}" >
        <beans:property name="driverClassName">
        <beans:value>${jdbc.driverClassName}</beans:value>
        </beans:property>
        </beans:bean>
    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>
    <context:component-scan base-package="jp.co.rns" />

    <mvc:interceptors>
    <beans:bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <beans:property name="paramName" value="lang" />
    </beans:bean>
    <beans:bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor">
        <beans:property name="paramName" value="lang" />
    </beans:bean>
    </mvc:interceptors>

    <beans:bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <beans:property name="basename" value="classpath:static" />
    <beans:property name="defaultEncoding" value="UTF-8"/>
</beans:bean>

<beans:bean id="localeChangeInterceptor"
    class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <beans:property name="paramName" value="lang" />
</beans:bean>

<beans:bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
    <beans:property name="defaultLocale" value="en"/>
</beans:bean> 

<!-- For Themes -->
<beans:bean id="themeSource"
    class="org.springframework.ui.context.support.ResourceBundleThemeSource">
        <beans:property name="basenamePrefix" value="theme_" />
</beans:bean>

<!-- Theme Change Interceptor and Resolver definition -->
<beans:bean id="themeChangeInterceptor"
    class="org.springframework.web.servlet.theme.ThemeChangeInterceptor">
    <beans:property name="paramName" value="lang" />     
</beans:bean>
<beans:bean id="themeResolver"
    class="org.springframework.web.servlet.theme.CookieThemeResolver">
    <beans:property name="defaultThemeName" value="en" />    
</beans:bean>
<beans:bean id="handlerMapping"
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <beans:property name="interceptors">
    <beans:list>            
        <beans:ref bean="themeChangeInterceptor" />
        <beans:ref bean="localeChangeInterceptor" />
    </beans:list>
    </beans:property>
</beans:bean>
</beans:beans>
  • 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-12T15:44:31+00:00Added an answer on June 12, 2026 at 3:44 pm

    I found the reason:

    @Id
    @Column(name="username")
    private String username;
    

    primary key must be autogenerated int, not string;

    I have restructured my table; DBUnit works now

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

Sidebar

Related Questions

To use Spring Integration in a Spring XML configuration file, I need to declare
I am trying to use Spring to inject @PersistenceContext entityManager into my service. The
In prior versions of spring (3.0), it was possible to test your controllers via
My wsdl is as follows, I use Spring-WS. For some test purposes I want
i currently build an application use spring as framework. and i want to test
I am trying to set up a database test using Spring and DBUnit. I
I try to use Spring framework with @Autowired annotation to get a Service class.
I'm trying to use spring-test-mvc for testing a controller in my little application. Since
I use Ubuntu and installed cURL on it. I want to test my Spring
I use Spring and Spring MVC 3.1, Hibernate 3, Hibernate Validator 4.3. I want

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.