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

查看:26
本文介绍了Spring Boot 加载 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 加载 orm.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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