我正在使用hyperjaxb3,它成功地解决了我的大部分问题。
然而,我花了一整个上午的问题,我无法解决。很可能是那些我完全忽略的愚蠢的东西之一,但我找不到它。
问题是,在bindings.xjb内部,我试图为我的一个实体更改生成的表名,但是无论我尝试什么,我设置的值都被完全忽略了。
以下是相关文件的内容:
XSD文件(只是一个片段)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://.../es/xbrl/eu/model/concept-statement" xmlns:fws="http://.../es/xbrl/eu/model/concept-statement">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>
<xs:element name="structure">
<xs:complexType>
<xs:sequence>
<xs:element ref="fws:module"/>
</xs:sequence>
</xs:complexType>
</xs:element>bindings.xjb
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
version="2.1"
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"
jaxb:extensionBindingPrefixes="hj orm">
<jaxb:bindings schemaLocation="concept-statement.xsd" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="es.company.cirbe.cubo.hechos.modelo"/>
</jaxb:schemaBindings>
<jaxb:globalBindings localScoping="toplevel">
<jaxb:serializable/>
</jaxb:globalBindings>
<jaxb:bindings node="xs:element[@name='structure']">
<hj:entity>
<orm:table name="FACTS_STRUCTURE"/>
</hj:entity>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>pom.xml (只是依赖关系和构建部分)
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>hyperjaxb3-ejb-runtime</artifactId>
<version>0.6.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>maven-hyperjaxb3-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<debug>false</debug>
<extension>true</extension>
<variant>ejb</variant>
<generateDirectory>src/main/java</generateDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/persistence.xml</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>生成的java文件
@XmlRootElement(name = "structure")
@Entity(name = "Structure")
@Table(name = "STRUCTURE_")
@Inheritance(strategy = InheritanceType.JOINED)
public class Structure
implements Serializable, Equals, HashCode
{
}我确信绑定文件正在读取:我已经检查了maven日志,如果我为xpath表达式设置了一些奇怪的值,就会得到一个与它们相关的运行时异常。
此外,它不仅忽略了表名自定义。我尝试更改实体名称、架构、为一个简单属性设置不同的列长度.在所有这些测试中,输出总是与上面复制的相同。
我也检查了现有的样本,但是我看不出我做错了什么。
问候
发布于 2015-09-18 06:18:37
好的,发现了这个问题,它与我的XSD文件的结构有关。
只是使用
xs:element[@name='structure']在我的绑定文件是不够的。正如看起来的那样,表映射定制只在与complexTypes关联时才能工作,所以当我将它更改为
xs:element[@name='structure']/xs:complexType一切如预期:)
希望这能对将来的人有所帮助。
https://stackoverflow.com/questions/32631708
复制相似问题