[英]Adding columnDefinition property to Hyperjaxb generated @Column attribute
I am using Hyperjaxb to generate my JPA mappings. 我正在使用Hyperjaxb生成我的JPA映射。 Then I use hibernate3-maven-plugin to generate the SQL Script of the database.
然后,我使用hibernate3-maven-plugin生成数据库的SQL脚本。 My problem lies in the fact that I have a type that has a property defined like this:
我的问题在于,我的类型具有定义如下的属性:
<xsd:element name="priority" type="xsd:boolean"/>
The sql script defines the column like this sql脚本定义这样的列
PRIORITY bit,
And the JPA entity defines it like this JPA实体是这样定义的
/**
* Obtient la valeur de la propriété priority.
*
*/
@Basic
@Column(name = "PRIORITY")
public boolean isPriority() {
return priority;
}
/**
* Définit la valeur de la propriété priority.
*
*/
public void setPriority(boolean value) {
this.priority = value;
}
I am using MySql as a backend. 我正在使用MySql作为后端。 The problem raises when my JPA/Hibernate entityManager tries to validate my JPA model against the database.
当我的JPA / HibernateEntityManager尝试针对数据库验证我的JPA模型时,就会出现此问题。 Then I get this error
然后我得到这个错误
org.hibernate.HibernateException: Wrong column type in custom.sample_type for column PRIORITY. Found: bit, expected: boolean
How can I fix this error? 如何解决此错误? Somewhere I read I could do something like this in java code
我读过的某处我可以在Java代码中做类似的事情
@Basic
@Column(name = "B", columnDefinition = "BIT", length = 1)
public boolean isB() {
return b;
}
But my JPA java code is autogenerated by Hyperjaxb, so how can I achieve something like that with Hyperjaxb? 但是我的JPA Java代码是由Hyperjaxb自动生成的,那么如何使用Hyperjaxb实现类似的功能?
Disclaimer: I am the author of Hyperjaxb . 免责声明:我是Hyperjaxb的作者。
I'd try customizing your property with: 我会尝试通过以下方式自定义您的媒体资源:
<hj:basic>
<orm:column column-definition="..."/>
</hj:basic>
See the customizations schema and the ORM schema it uses. 请参阅自定义架构及其使用的ORM架构 。
You can also configure per-type customizations if you don't want to customize every single boolean (which you probably don't want): 如果您不想自定义每个布尔值(您可能不希望这样),也可以配置每个类型的自定义:
<hj:default-single-property type="xsd:boolean">
<hj:basic>
<orm:column column-definition="..."/>
</hj:basic>
</hj:default-single-property>
<hj:default-collection-property type="xsd:boolean">
<hj:element-collection>
<orm:column column-definition="..."/>
</hj:element-collection>
</hj:default-collection-property>
See this example of a binding file: 请参阅以下绑定文件示例 :
<?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"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="hj orm annox">
<jaxb:bindings schemaLocation="schema.xsd" node="/xs:schema">
<jaxb:schemaBindings>
<jaxb:package name="org.jvnet.hyperjaxb3.ejb.tests.pocustomized"/>
</jaxb:schemaBindings>
<hj:persistence>
<hj:default-generated-id name="MySuperId" transient="true">
<orm:column name="MY_SUPER_ID"/>
</hj:default-generated-id>
<hj:default-one-to-many>
<orm:join-table/>
</hj:default-one-to-many>
</hj:persistence>
<jaxb:bindings node="xs:complexType[@name='one']/xs:sequence/xs:element[@name='many-to-many-join-table']">
<annox:annotate>
<annox:annotate annox:class="org.hibernate.annotations.Cascade" value="DELETE_ORPHAN"/>
</annox:annotate>
</jaxb:bindings>
<jaxb:bindings node="xs:element[@name='ten']/xs:complexType">
<hj:basic name="content">
<orm:column length="1024"/>
</hj:basic>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
You'll have to place your hj:default-...-property
elements inside hj:persistence
. 您必须将
hj:default-...-property
元素放入hj:persistence
。 They will then override default mappings. 然后,它们将覆盖默认映射。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.