首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Hyperjaxb3导入的XSD和persistence.xml

Hyperjaxb3导入的XSD和persistence.xml
EN

Stack Overflow用户
提问于 2018-12-11 19:58:12
回答 1查看 100关注 0票数 0

这是我第一次尝试使用Hyperjaxb3。我有我的2XSD的一个片段,如下所示

ContractFullInfo.xsd

代码语言:javascript
复制
<xsd:import namespace="http://homecredit.net/homerselect/common/v1" schemaLocation="Common.xsd"/>

<xsd:element name = "ContractFullInfoRequest">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="systemEvent" type="common:ContractSystemEventType"/>
            <xsd:element name="data" type="ContractFullInfo"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

<xsd:complexType name="ContractPerson">
    <xsd:sequence>
        <xsd:element name="cuid" type="xsd:long"/>
        <xsd:element name="personRole" type="PersonRoleType"/>
    </xsd:sequence>
</xsd:complexType>

Common.xsd

代码语言:javascript
复制
<xsd:complexType name="ContractPerson">
    <xsd:sequence>
        <xsd:element name="cuid" type="xsd:long"/>
        <xsd:element name="personRole" type="PersonRoleType"/>
    </xsd:sequence>
</xsd:complexType>

问题是它生成了两个ContractPerson类,如下所示:

代码语言:javascript
复制
        <class>net.homecredit.homerselect.common.v1.ContractPerson</class> <==
        <class>net.homecredit.homerselect.common.v1.MoneyDto</class>
        <class>net.homecredit.homerselect.contract.v3.BankAccount</class>
        <class>net.homecredit.homerselect.contract.v3.ClosedEndParameter</class>
        <class>net.homecredit.homerselect.contract.v3.ContractBase</class>
        <class>net.homecredit.homerselect.contract.v3.ContractCommodity</class>
        <class>net.homecredit.homerselect.contract.v3.ContractDocument</class>
        <class>net.homecredit.homerselect.contract.v3.ContractEvent</class>
        <class>net.homecredit.homerselect.contract.v3.ContractFullInfo</class>
        <class>net.homecredit.homerselect.contract.v3.ContractFullInfoRequest</class>
        <class>net.homecredit.homerselect.contract.v3.ContractParameter</class>
        <class>net.homecredit.homerselect.contract.v3.ContractPerson</class> <==
        <class>net.homecredit.homerselect.contract.v3.ContractService</class>
        <class>net.homecredit.homerselect.contract.v3.RefinancedContract</class>
        <class>net.homecredit.homerselect.contract.v3.RevolvingParameter</class>

在部署期间,它会给我一个错误,因为

代码语言:javascript
复制
 Entity name must be unique in a persistence unit. Entity name [ContractPerson] is used for the entity classes [net.homecredit.homerselect.common.v1.ContractPerson] and [net.homecredit.homerselect.contract.v3.ContractPerson].

我的Java配置的一部分(我目前对其进行了注释)

代码语言:javascript
复制
  @Bean
    public DataSource dataSource() throws NamingException {
        return (DataSource) new JndiTemplate().lookup(env.getProperty("spring.datasource.jndi-name"));
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws NamingException {
        LocalContainerEntityManagerFactoryBean em
                = new LocalContainerEntityManagerFactoryBean();
        em.setPackagesToScan(new String[]{"net.homecredit.homerselect.contract.v3"});
        em.setPersistenceUnitName("net.homecredit.homerselect.common.v1:net.homecredit.homerselect.contract.v3");
        em.setJtaDataSource(dataSource());

        Properties properties = new Properties();
        properties.setProperty("hibernate.dialect", env.getProperty("spring.jpa.properties.hibernate.dialect"));
        properties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("spring.jpa.hibernate.ddl-auto"));
        em.setJpaProperties(properties);

        return em;
    }

我的问题:

  1. 这两个类是完全相同的。
  2. 我正在使用Spring Boot,有没有办法使用Spring Boot java configuration?

来覆盖persistence.xml

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-12 04:15:40

您的类是不同的,因为您的架构中有两个不同的复杂类型。它们可能还引用了不同的PersonRoleType,但是如果看不到完整的模式就很难说。

虽然将这些复杂类型映射到同一个Java类并不是不可能的,但我不会这么做。这些类型在模式中是不同的类型,在Java中也应该保持不同。

由于您遇到具有相同本地名称的类的问题,因此最简单的解决方案是重命名其中一个类。使用如下绑定:

代码语言:javascript
复制
<jaxb:bindings
    version="1.0"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:hj="http://hyperjaxb3.jvnet.org/ejb/schemas/customizations"
    xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:extensionBindingPrefixes="xjc hj orm">

    <jaxb:bindings schemaLocation="Common.xsd" node="/xs:schema">
        <jaxb:bindings node="xs:complexType[@name='ContractPerson']">
            <jaxb:class name="CommonContractPerson"/>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53723733

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档