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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:48:11+00:00 2026-06-10T19:48:11+00:00

I have a small Spring web application, with the typical MVC Service DAO JPA/Hibernate

  • 0

I have a small Spring web application, with the typical MVC Service DAO JPA/Hibernate Persistence Layer architecture. In production, I use a JTA-like persistence unit. The DAO is injected with an instance of the EntityManager via @PersistenceContext by the container. All is fine.

Now, I want to test my DAO implementations using an in-memory database (outside of a container on my local pc). I could manually create a RESOURCE_LOCAL based EntityManager. But how can I have it injected in my DAO implementations automatically?

I have seen this question and it suggests that it is possible with Spring. But how?

Of course, for unit testing, I could use new MyDAOImpl() and inject the EntityManager myself, but later, I will want to test my services which are injected with DAO implementations. I would like to avoid having to wire everything myself… Is this possible?

  • 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-10T19:48:13+00:00Added an answer on June 10, 2026 at 7:48 pm

    In our project, we define a different unit-testing-config.xml that has the datasource bean defined to point the in-memory database as follows:

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="driverClass" value="org.hsqldb.jdbc.JDBCDriver" />
            <property name="jdbcUrl"
                    value="jdbc:hsqldb:file:/data/data.db" />
            <property name="user" value="sa" />
            <property name="password" value="" />
            <property name="initialPoolSize" value="1" />
            <property name="minPoolSize" value="1" />
            <property name="maxPoolSize" value="50" />
            <property name="maxIdleTime" value="240" />
            <property name="checkoutTimeout" value="60000" />
            <property name="acquireRetryAttempts" value="0" />
            <property name="acquireRetryDelay" value="1000" />
            <property name="numHelperThreads" value="1" />
    </bean>
    

    The normal entityManagerFactory defintion as follows will use the above datasource bean:

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="persistenceUnitName" value="myDoctorPersistenceUnit" />
        <property name="loadTimeWeaver">
            <bean
                class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
        </property>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="generateDdl" value="true" />
                <property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect" />
            </bean>
        </property>
        <property name="jpaDialect" ref="jpaDialect" />
    </bean>
    

    And we run our TestSuite using the following annotations:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations ={ "/spring-configuration/test-spring.xml" })
    

    Hope this helps!

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

Sidebar

Related Questions

The environment of my application: web-based, Spring MVC+Security, Hibernate, MySQL(InnoDB) I am working on
I have small problem with Spring MVC. Basically what I'm trying to do is
I am developing a small Spring application. I have to store the details of
I have a spring web application (currently packaged as a war file) which I
I have a small Spring (3.1.0.RELEASE) application, which was working just fine, until I
I am looking for a web based report designer supporting spring/hibernate. I have seen
I have this idea for a small-medium web application that I would like to
I have been writing a small web application in C# .NET4.0 to try and
I'm building a Web-application in java, with Spring (and spring security), struts2 and hibernate.
i have made a small web application with form.html output.jsp ServletOne.java In the form.html,users

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.