I am using Hyperjaxb to generate my JPA mappings. Then I use hibernate3-maven-plugin to generate the SQL Script of the database. 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
PRIORITY bit,
And the JPA entity defines it like this
/**
* 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. The problem raises when my JPA/Hibernate entityManager tries to validate my JPA model against the database. 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
@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?
Disclaimer: I am the author of 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.
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
. They will then override default mappings.