我有一个看起来像的模式片段
<xs:element name="dataValue">
<xs:complexType>
<xs:sequence>
<xs:element name="value" type="xs:anyType"\>
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
hyperjaxb3生成的类包含以下片段:
@XmlElement(required = true)
protected Object value;
@Transient
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
@Basic
@Column(name = "VALUEOBJECT")
public String getValueObject() {
if (JAXBContextUtils.
isMarshallable("org.lcogt.schema", this.getValue())) {
return JAXBContextUtils.unmarshall("org.lcogt.schema", this.getValue());
} else {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,hibernate将很难持久化纯对象,因此hyperjaxb假设该对象可以被解组为XML字符串并且生成的String是持久的.在我的情况下,这不是真的,但我可以保证toString()方法将返回一些有用的东西.我希望生成的代码看起来更像:
@XmlElement(required = true)
protected Object value;
@Transient
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = …Run Code Online (Sandbox Code Playgroud) 我使用Hyperjaxb从XML模式生成一些带有JPA注释的类.我想指定给定模式xjc应该生成哪些元素.我无法更改xsd文件.我只能修改bindings.xjb.我试图使用hj:忽略,但没有成功.
需要:接受XML并将数据保存到数据库.
目前使用:JAXB将XML Schema转换为java类.然后我打算使用JPA来持久化由JAXB编组的对象.
问题:我想要一些东西来弥补差距.在JAXB生成Java类之后,我必须使用@Temporal手动注释所有java.util.Date字段; 我必须将@Entity放在每个生成的类的顶部......等等.
我遇到了Hyperjaxb.但我可以找到很少的文档,但无法使其工作.
我对完全不同的方法持开放态度.这似乎是一个常见的问题,所以也许有一个通用的解决方案.
我有一个模式,JAXB每次都能完美地生成 java 类。我正在尝试hyperjaxb处理相同的模式。为此,我从此链接hyperjaxb下载并解压了Maven 项目,然后使用
示例数据导航到根目录,并通过运行来测试它,以确保它适用于示例架构。然后,我用在 中完美运行的完整模式替换了、和文件,包括许多导入的命名空间。然后我又跑了。但是,我收到以下错误消息:cmd.exemvn clean installschema.xsdpo.xmlbindings.xjbJAXBmvn clean install
[ERROR] Error while parsing schema(s).Location [ file:/C:/path/to/src/main/resources/schema.xsd{4,32}].
org.xml.sax.SAXParseException; systemId: file:/C:/path/to/src/main/resources/schema.xsd;
lineNumber: 4; columnNumber: 32; Unsupported binding namespace "".
Perhaps you meant "http://annox.dev.java.net"?
Run Code Online (Sandbox Code Playgroud)
在示例中,schema.xsd 顶部的架构标记为:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">
Run Code Online (Sandbox Code Playgroud)
相比之下,我的自定义架构使用:
<xs:schema targetNamespace="urn:some-org:v3" xmlns:mif="urn:some-org:v3/mif" xmlns="urn:some-org:v3"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:sdtc="urn:some-org:sdtc" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">
Run Code Online (Sandbox Code Playgroud)
请注意xmlns="urn:some-org:v3"我的自定义架构中的架构标记。它不包括像 之类的限定符xmlns:somequalifier="urn:some-org:v3"。这是造成问题的原因吗?它在 JAXB 中完美运行,无需限定符。遍历整个命名空间并在每个类型前面添加限定符将是一个很大的痛苦。
或者,也可能是示例项目的 pom.xml 中定义的结构(在上面链接的 zip 文件中)导致了问题。它们与基本的 JAXB 工具不同。
我怎样才能避免这个问题? 最好不要为每种类型添加限定符。我的架构中有几千行。
堆栈跟踪的以下几行可能会有所启发: …
我是JPA/Hyperjaxb竞技场的新手.我的目标是在Author和Book表(postgres数据库)之间生成多对多映射.
在数据库中 - 作者表有列--id,name和Book表有列--id,title.我有一个联结(链接)表AUTHORS_BOOKS,它有列辅助,bid(其中援助映射到Author表中的id字段,bid表映射到Book表中的id字段).
我们正在公开一个Web服务(不要专注于Web服务的原因),以允许客户查询/讨论作者和书籍.对于web服务,我正在使用hyperjaxb符号创建pojos(再次就是它如何).
这是我的types.xsd文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
Run Code Online (Sandbox Code Playgroud)
<xs:complexType name="author">
<xs:sequence>
<xs:element name="id" type="xs:long"/>
<xs:element name="name" type="xs:string" />
<xs:element name="books" type="tns:book" minOccurs="0" maxOccurs="1000"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="book">
<xs:sequence>
<xs:element name="id" type="xs:long"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="authors" type="tns:author" minOccurs="0" maxOccurs="1000"/>
</xs:sequence>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
这是bindings.xjb文件:
<?xml version="1.0" encoding="UTF-8"?>
Run Code Online (Sandbox Code Playgroud)
<jaxb:bindings schemaLocation="sampletypes.xsd"
node="/xs:schema">
<jaxb:bindings node="xs:complexType[@name='author']">
<hj:entity>
<orm:table name="AUTHORS">
<orm:unique-constraint>
<orm:column-name>NAME</orm:column-name>
</orm:unique-constraint>
</orm:table>
</hj:entity>
</jaxb:bindings>
<jaxb:bindings node="xs:complexType[@name='cocom']">
<hj:entity>
<orm:table name="BOOKS">
<orm:unique-constraint>
<orm:column-name>NAME</orm:column-name>
</orm:unique-constraint>
</orm:table>
</hj:entity>
</jaxb:bindings>
<jaxb:bindings
node="xs:complexType[@name='author']//xs:element[@name='books']">
<hj:many-to-many name="books">
<orm:join-table name="AUTHORS_BOOKS">
<orm:join-column name="aid" …Run Code Online (Sandbox Code Playgroud) 我们使用HyperJAXB生成了一些(很多)类.所有类都实现了Equals和HashCode,并具有下面的实现风格.看来这个代码永远不会执行..有什么特别的原因我们需要这个代码吗?如果可以的话,我正在寻求简化课程.
public boolean equals(Object object) {
if (!(object instanceof MyClass)) {
return false;
}
if (this == object) {
return true;
}
final EqualsBuilder equalsBuilder = new JAXBEqualsBuilder();
equals(object, equalsBuilder);
return equalsBuilder.isEquals();
}
public void hashCode(HashCodeBuilder hashCodeBuilder) {
hashCodeBuilder.append(this.getValue());
hashCodeBuilder.append(this.getId());
}
public int hashCode() {
final HashCodeBuilder hashCodeBuilder = new JAXBHashCodeBuilder();
hashCode(hashCodeBuilder);
return hashCodeBuilder.toHashCode();
}
Run Code Online (Sandbox Code Playgroud) 我知道 Hyperjaxb3 库对我的项目非常有用,在多个站点上阅读了一些描述,并决定将它嵌入到我的 Spring-Hibernate 项目中。
我在https://jaxb.java.net/ 中找到了对 Hyperjaxb3 的引用,看起来很官方,但是超链接 - http://confluence.highsource.org/display/HJ3/Home - 没有打开。
我找到了一些旧的 POM 示例,将其包含在我的项目中,并找到了一些旧版本的引用,试图消除它们,但现在似乎我遇到了对旧 Hibernate 版本的依赖,错误就像这个:
java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Provider org.jvnet.hyperjaxb3.hibernate.plugin.HibernatePlugin 无法实例化: java.lang.NoClassDefFoundError: org/hibernate/type/MutableType
我想知道是否有更好的 Maven 条目,项目是否还活着以及如何将它与现代 Hibernate 一起使用。
这是我关于 Hyperjaxb3 的 pom 摘录,其中我排除了一些过时的链接并指定了其他依赖项的最新版本:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-core</artifactId>
<version>${jaxb-version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>${jaxb-version}</version>
</dependency>
<!--<dependency>
<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>hyperjaxb3</artifactId>
<version>0.6.1</version>
</dependency> -->
<dependency>
<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>hyperjaxb3-hibernate-plugin</artifactId>
<version>0.1</version>
<exclusions>
<exclusion>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon-dom</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId> …Run Code Online (Sandbox Code Playgroud) 我想将本教程中的示例应用程序导入到eclipse中.我一直收到与文件放置位置有关的错误.当我创建一个Main类来运行教程中的代码时,我得到Eclipse的编译错误,当Main类在构建路径中时,没有看到所需的包,或者我得到了一个
启动错误:Section不包含主类型
当Main类不在构建路径中时.
到目前为止,我已采取以下步骤:
上述步骤导致上述错误. 什么是在Eclipse中使其工作的分步说明?