Spring Boot Load orm.xml [英] Spring Boot Load orm.xml

查看:106
本文介绍了Spring Boot Load orm.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Jpa的自定义映射外部化为XML文件.我已经看到了使用orm.xml的示例,但是当我在resources/META-INF中创建orm.xml时,似乎没有被加载.我看到的所有示例都是通过persistence.xml加载的,而Spring Boot却没有.我没有太多寻找答案.如何使Spring Boot加载orm.xml文件?

I want to externalize my custom mappings for Jpa to an XML file. I've seen examples of using orm.xml however when I create orm.xml in resources/META-INF it does not appear to be loaded. All the examples I've seen it gets loaded through persistence.xml, which I don't have with Spring Boot. I didn't turn up much searching for answers. How do I make Spring Boot load my orm.xml file?

orm.xml示例

<entity-mappings version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm
    http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd">
<sql-result-set-mapping name="AuthorMappingXml">
    <entity-result entity-class="org.thoughts.on.java.jpa.model.Author">
        <field-result name="id" column="authorId"/>
        <field-result name="firstName" column="firstName"/>
        <field-result name="lastName" column="lastName"/>
        <field-result name="version" column="version"/>
    </entity-result>
</sql-result-set-mapping>
<sql-result-set-mapping name="AuthorBookCountMappingXml">
    <entity-result entity-class="org.thoughts.on.java.jpa.model.Author">
        <field-result name="id" column="id"/>
        <field-result name="firstName" column="firstName"/>
        <field-result name="lastName" column="lastName"/>
        <field-result name="version" column="version"/>
    </entity-result>
    <column-result name="bookCount" class="java.lang.Long" />
</sql-result-set-mapping>
<sql-result-set-mapping name="BookAuthorMappingXml">
    <entity-result entity-class="org.thoughts.on.java.jpa.model.Author">
        <field-result name="id" column="authorId"/>
        <field-result name="firstName" column="firstName"/>
        <field-result name="lastName" column="lastName"/>
        <field-result name="version" column="authorVersion"/>
    </entity-result>
    <entity-result entity-class="org.thoughts.on.java.jpa.model.Book">
        <field-result name="id" column="id"/>
        <field-result name="title" column="title"/>
        <field-result name="author" column="author_id"/>
        <field-result name="version" column="version"/>
    </entity-result>
</sql-result-set-mapping>
<sql-result-set-mapping name="BookValueMappingXml">
    <constructor-result target-class="org.thoughts.on.java.jpa.value.BookValue">
        <column name="id" class="java.lang.Long"/>
        <column name="title"/>
        <column name="version" class="java.lang.Long"/>
        <column name="authorName"/>
    </constructor-result>
</sql-result-set-mapping>
</entity-mappings>

推荐答案

好的错误警报,默认情况下,Spring Boot会加载它,但是我的Intellij/Gradle设置存在另一个问题,即未部署最新版本/WAR因此它在没有orm.xml的情况下进行了部署.我必须进行gradle清理,并使Intellij中的缓存无效并重新启动.

Okay false alarm, it appears Spring Boot loads it by default, however my Intellij / Gradle setup had another issue, where it was not deploying the latest build / WAR so it deployed without the orm.xml. I had to do a gradle clean, and invalidate the cache in Intellij and restart.

这篇关于Spring Boot Load orm.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆