我正在尝试使用 hyperjaxb 生成带 JPA 注释的 java 类,但遇到了一个问题。欢迎任何建议:-
部分..Pom.xml
<!-- hyperjaxb -->
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>maven-hyperjaxb3-plugin</artifactId>
<version>0.5.6</version>
</dependency>
...
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>maven-hyperjaxb3-plugin</artifactId>
<version>0.5.6</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<executions>
<execution>
<id>1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<forceRegenerate>true</forceRegenerate>
<schemaDirectory>${basedir}/src/main/resources/schemas/demo</schemaDirectory>
<schemaIncludes>
<schemaInclude>demo.xsd</schemaInclude>
</schemaIncludes>
<generatePackage>com.fsi.demo</generatePackage>
<strict>true</strict>
<extension>true</extension>
</configuration>
</execution>
</executions>
</plugin>
这是 demo.xsd:-
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="demo">
<xs:complexType>
<xs:sequence>
<xs:element ref="playerID" />
<xs:element ref="G"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="playerID" type="xs:string" />
<xs:element name="G" type="xs:string" />
</xs:schema>
这是生成的java类
public class Demo
implements Equals, HashCode
{
@XmlElement(required = true)
protected String playerID;
@XmlElement(name = "G", required = true)
protected String g;
@XmlAttribute(name = "Hjid")
protected Long hjid;
....
...
/**
* Gets the value of the g property.
*
* @return
* possible object is
* {@link String }
*
*/
@Basic
@Column(name = "G_", length = 255)
public String getG() {
return g;
}
/**
* Sets the value of the g property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setG(String value) {
this.g = value;
}
}
额外的下划线 @Column(name = "G_", length = 255) 正在破坏我的代码,因为休眠抱怨无效的列映射。
到目前为止我尝试过的对问题没有影响:- 1)demo.xsd 中的内联自定义绑定
<xs:annotation>
<xs:appinfo>
<jxb:property name="G" />
</xs:appinfo>
</xs:annotation>
和
<xs:annotation>
<xs:appinfo>
<orm:attribute-override name="G">
<orm:column name="G" />
</orm:attribute-override>
</xs:appinfo>
</xs:annotation>
我在这里想念什么,请任何人!
更新: 下面的休眠查询:-休眠:
选择 demo0_.PLAYERID 作为 PLAYERID1_0_,demo0_.G_ 作为 G_2_0_ 从 DEMO demo0_ where demo0_.PLAYERID in (?)
痕迹:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'demo0_.G_' in 'field list'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
正确的是,实际列是G而不是由 hyperjaxb 生成的G_ ,将其更改为 G(手动)解决了这个问题