Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hyperjaxb 3导入了XSD和persistence.xml_Java_Xml_Hyperjaxb - Fatal编程技术网

Java Hyperjaxb 3导入了XSD和persistence.xml

Java Hyperjaxb 3导入了XSD和persistence.xml,java,xml,hyperjaxb,Java,Xml,Hyperjaxb,这是我第一次尝试使用Hyperjaxb3。我有一个XSD的片段,如下所示 ContractFullInfo.xsd <xsd:complexType name="ContractPerson"> <xsd:sequence> <xsd:element name="cuid" type="xsd:long"/> <xsd:element name="personRole" type="PersonRoleType"/

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

ContractFullInfo.xsd

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

我的Java配置的一部分(我目前对此进行了评论)

我的问题是:

  • 这两个类完全相同。我怎么选一个
  • 我使用的是SpringBoot,有没有办法使用SpringBootJava配置来覆盖persistence.xml
    您的类不同,因为您的模式中有两种不同的复杂类型。它们也可能引用不同的
    PersonRoleType
    s,但很难说没有看到完整的模式

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

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

    <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>
    
    
    
            <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>
    
     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].
    
      @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;
        }
    
    <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>