[JAVA] How to define multiple orm.xml in Spring4, JPA2.1


The definition method when managing multiple orm.xml (user.xml, userImage.xml) is described below. Orm.xml in this article means a file that defines entity-mappings such as entity and native-sql. If you search, there is a lot of information on how to define META-INF / persistence.xml and META-INF / orm.xml. This is the definition when using JPA alone, so a different definition is required when using it in combination with Spring4.

Package configuration

     | |_☓☓☓
     | |_☓☓☓
     | |_user.xml
     | |_userImage.xml


This time, we will use the following version. spring-data-jpa: 1.10.5.RELEASE hibernate-entitymanager: 5.1.0.Final

--maven definition

        <!-- JPA -provider(Hibernate) -->

applicationContext.xml definition

The following is a definition example of applicationContext.xml. You can also create a file such as dataSource.xml and import it for all settings for DB connection. To define multiple orm.xml, use mappingResources of property. Define the path under the root of the created orm.xml (user.xml, userImage.xml this time). If you want to increase orm.xml, you need to add it below.

As an aside, if you use only one orm.xml, you can define the file name orm.xml directly under the META-INF directory. , It can be read without the definition of mappingResource below.

Definition example

<jpa:repositories base-package="com.sample.orm.dao"/>
<!-- mysql -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driver.class}"/>
    <property name="url">
    <property name="username" value="${jdbc.user}"/>
    <property name="password" value="${jdbc.pass}"/>
    <property name="maxActive" value="20"/>
    <property name="maxIdle" value="1"/>

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

<bean id="entityManagerFactory"
    <!--entity directory definition-->
    <property name="packagesToScan" value="com.sample.orm.entity"/>
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="false"/>
            <property name="generateDdl" value="false"/>
            <property name="database" value="MYSQL"/>
    <property name="jpaProperties">
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
    <!--Define mapping path-->
    <property name="mappingResources">

Recommended Posts

How to define multiple orm.xml in Spring4, JPA2.1
How to use Lombok in Spring
[How to install Spring Data Jpa]
How to execute multiple commands in docker-compose.yml
How to add a classpath in Spring Boot
How to create a Spring Boot project in IntelliJ
How to use CommandLineRunner in Spring Batch of Spring Boot
How to test file upload screen in Spring + Selenium
How to use In-Memory Job repository in Spring Batch
How to change application.properties settings at boot time in Spring boot
How to call and use API in Java (Spring Boot)
How to control transactions in Spring Boot without using @Transactional
How to unit test Spring AOP
How to run JUnit in Eclipse
How to iterate infinitely in Ruby
How to use Spring Data JDBC
[Rails] How to write in Japanese
How to run Ant in Gradle
How to master programming in 3 months
How to set Spring Boot + PostgreSQL
How to learn JAVA in 7 days
How to get parameters in Spark
How to install Bootstrap in Ruby
How to use ModelMapper (Spring boot)
How to introduce jQuery in Rails 6
How to use classes in Java?
How to name variables in Java
How to set Lombok in Eclipse
[Swift] How to replace multiple strings
How to concatenate strings in java
How to install Swiper in Rails
How to set and use profile in annotation-based Configuration in Spring framework
How to call multiple names at once in the same category
[swift5] How to specify color in hexadecimal
How to implement search functionality in Rails
How to implement Kalman filter in Java
How to change app name in rails
How to get date data in Ruby
How to use custom helpers in rails
How to read Body of Request multiple times with Spring Boot + Spring Security
How to implement a slideshow using slick in Rails (one by one & multiple by one)
Note to have multiple values in HashMap
How to reflect seeds.rb in production environment
How to use named volume in docker-compose.yml
How to filter JUnit Test in Gradle
Convert request parameter to Enum in Spring
How to insert a video in Rails
How to standardize header footer in Thymeleaf
Exists using Specification in Spring Data JPA
How to add jar file in ScalaIDE
[Swift] How to fix Label in UIPickerView
How to use Docker in VSCode DevContainer
How to use MySQL in Rails tutorial
How Dispatcher servlet works in Spring MVC
How to define an inner class bean
How to embed Janus Graph in Java
[rails] How to configure routing in resources
To write Response data directly in Spring
How to map tsrange type in Hibernate
How to get the date in java
How to not start Flyway when running unit tests in Spring Boot