0

I have a SpringBoot 2.0 application, and I've decided to mix annotations and XML configuration using orm.xml. So, I've put orm.xml (JPA file with XML configuration) in resources/META-INF, and, when starting the application, it's taken into account and everything is good, it works like a charm.

However, when running integration tests (which use an in-memory database), orm.xml seems to be completely ignored, as the test fails with an exception related to a missing mapping, mapping which I've written in orm.xml (an embeddable entity).

Here's how a test looks like:

package hello;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
@DataJpaTest
public class ApplicationTests {

    @Test
    public void contextLoads() {
    }

}

I've also tried @AutoConfigureTestDatabase instead of @DataJpaTest, but with no success.

What should I change, in order for the integration test to load orm.xml?

2
  • is it in persistence.xml? or whatever excuse for a "standard" Spring use? Commented Feb 21, 2018 at 7:21
  • Check this .... stackoverflow.com/questions/32536200/… Commented Feb 21, 2018 at 13:08

2 Answers 2

0

I had to migrate some integration tests that used an in-memory database to SpringBoot2 and in order to have access to the "orm.xml" file in the tests I just copied it from "src/main/resources/META-INF/orm.xml" to "src/test/resources/META-INF/orm.xml".

Sign up to request clarification or add additional context in comments.

Comments

-1

I was using spring with junit (not spring boot) and I used to annotate the test class like this :

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "appContextTest.xml" })

and inside the appContextTest.xml , I have the import :

<import resource="classpath:config-test.xml" />

EDIT : the file contents are like follows (it has the Datasource definition and hibernate properties :

<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
    <property name="URL" value="jdbc:oracle:thin:@127.0.0.1:1521:serv"/>
    <property name="user" value="us"/>
    <property name="password" value="pass"/>
</bean>
.

.

.
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop> 
        </props>
    </property>

` ... I don't know if that helps or no

1 Comment

I've tried this, but it doesn't work since the <import> tag imports XML bean definitions, while orm.xml is a JPA file, and therefore unrelated to Spring.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.