我正在尝试使用hyperjaxb生成JPA注释的java类,但遇到了一个问题。任何建议欢迎: -针对某些单个字符列在@column中生成的hyperjaxb额外下划线(_)
局部..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) 正在打破我的代码,因为hibernate抱怨无效的列映射。
我试了一下,到目前为止,这对这个问题没有影响: - 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>
我缺少什么在这里,请任何人!
UPDATE: Hibernate查询下面: - 休眠:
从 DEMO选择 demo0_.PLAYERID如PLAYERID1_0_, demo0_.G_如G_2_0_ demo0_ 其中 demo0_.PLAYERID在( ? )
微量:
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)
这是正确的为实际列摹和NOT G_由hyperjaxb产生,将其更改为G(手动)解决了这个问题
为什么列映射无效? – lexicore
由于hyperjaxb生成的列包含多余的_(** G _ **而不是** G **)。 **注:**更新了与上述 – AshDDN
更多的问题的详细信息原来的问题:XSD \t''也产生具有下划线的列名(_),像下面'@Basic @Column(名称= “名_”,长度= 255) 公共字符串的getName(){ 返回名称; }' –
AshDDN