Hello...
using hibernate-tools 3.2.0beta8
I seem to be stuck with this problem:
I am trying to map BINARY from the database as byte[] as explained in this link:
http://www.hibernate.org/73.html
(i made somme modifications to the original :) )
I got it to work but now I have to convince the reveng module to do it's job properly again...
so I need, for example, the logo to be mapped like this:
in the *.hbm file:
Code:
<property name="logo" type="org.kobit.ofam.service.dao.hibernate.usertype.BinaryBlobType">
and in the entity:
Code:
private byte[] logo;
I finaly solved the .hbm.xml file by using :
Code:
<sql-type jdbc-type="BINARY" hibernate-type="org.kobit.ofam.service.dao.hibernate.usertype.BinaryBlobType"/>
now I just have to convince hbm2java to declare logo as byte[]....
I allready have a custom template for hibernate tools so i changed property.hbm.ftl like this: ....
Code:
<#if property.value.hasFormula()>
<#assign formula = c2h.getFormulaForProperty(property)>
<#if formula?has_content>
formula="${formula.text}"
</#if>
>
<#if property.value.typeName.equals("org.kobit.ofam.service.dao.hibernate.usertype.BinaryBlobType")>
<meta attribute="property-type">java.lang.String</meta>
</#if>
<#else>
>
<#if property.value.typeName.equals("org.kobit.ofam.service.dao.hibernate.usertype.BinaryBlobType")>
<meta attribute="property-type">java.lang.String</meta>
</#if>
<#foreach column in property.columnIterator>
<#include "column.hbm.ftl">
</#foreach>
</#if>
</property>
this works too so now I have :
Code:
<property name="logo" type="org.kobit.ofam.service.dao.hibernate.usertype.BinaryBlobType">
<meta attribute="property-type">byte[]</meta>
<column name="LOGO" />
</property>
in my hbm.xml file... I thought this wold do the trick... but it dosen't ... logo is still declared as Serializable :( ... I tried replacing bytep[] with java.lang.String ... but it's still declared as Serializable....
below it's my build.xml .... hope it helps...
Code:
<?xml version="1.0" encoding="iso-8859-1" ?>
<project name="Hibertest Build Tasks" basedir="." default="reverse">
<property name="reveng.resources.dir" value="./src/main/resources/" />
<property name="resources.dir" value="${project.dir}business-layer/src/main/resources/" />
<property name="relative.resources.dir" value="./src/main/resources/" />
<property name="java.dir" value="${project.dir}business-layer/src/main/java/" />
<property name="generated.schema.dir" value="/org/kobit/ofam/service/dao/hsqldb/"/>
<property name="generated.schema.dtd.dir" value="/org/kobit/ofam/service/dao/testdata/"/>
<property name="generated.schema.dtd.name" value="OFAM-schema.dtd"/>
<property name="package.name" value="org.kobit.ofam.service.model"/>
<property name="package.dir" value="/org/kobit/ofam/service/model/"/>
<property name="reveng.dir" value="${reveng.resources.dir}org/kobit/ofam/reveng/"/>
<property name="database.url" value="jdbc:hsqldb:file:./database/ofam;shutdown=true"/>
<property name="template.dir" value="${reveng.resources.dir}org/kobit/ofam/reveng/template/"/>
<property name="rev.strategy" value="org.kobit.ofam.reveng.strategy.OFAMReverseEngineeringStrategy" />
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpath="${mvn.cp}"/>
<taskdef name="dbunit"
classname="org.dbunit.ant.DbUnitTask"
classpath="${mvn.cp}"/>
<target name="cleanDBunit">
<delete quiet="true">
<fileset dir="${project.dir}ofam-reveng/database/" includes="*.*"/>
</delete>
</target>
<target name="createTables" depends="cleanDBunit">
<echo message="Creating database tables"/>
<sql driver="org.hsqldb.jdbcDriver" url="${database.url}"
userid="sa" password="" delimiter=";" onerror="continue"
src="${reveng.dir}sql/ofamDb.sql" autocommit="true"
classpath="${mvn.cp}" caching="false">
</sql>
</target>
<target name="insertTestData">
<echo message="Insert test data"/>
<sql driver="org.hsqldb.jdbcDriver" url="${database.url}"
userid="sa" password=""
delimiter=";" onerror="continue"
src="${reveng.dir}sql/testdata.sql" autocommit="true"
classpath="${mvn.cp}" caching="false"/>
</target>
<target name="addConstraints">
<echo message="Adding tables constraints"/>
<sql driver="org.hsqldb.jdbcDriver" url="${database.url}"
userid="sa" password=""
delimiter=";" onerror="continue"
src="${reveng.dir}sql/constraints.sql" autocommit="true"
classpath="${mvn.cp}" caching="false"/>
</target>
<target name="generateDTD">
<dbunit driver="org.hsqldb.jdbcDriver"
url="${database.url}" userid="sa" password=""
classpath="${mvn.cp}">
<export dest="${resources.dir}${generated.schema.dtd.dir}${generated.schema.dtd.name}" format="dtd"/>
<export dest="${resources.dir}${generated.schema.dtd.dir}testdata.xml" format="flat"
doctype="${generated.schema.dtd.name}"/>
</dbunit>
</target>
<target name="delete">
<delete quiet="true">
<fileset dir="${resources.dir}${generated.schema.dir}" includes="hsqldb_schema.sql"/>
<fileset dir="${resources.dir}${package.dir}" includes="*.hbm.xml"/>
<fileset dir="${java.dir}${package.dir}" includes="*.java" excludes="EntityFactory.java"/>
</delete>
</target>
<target name="reverse" depends="delete" >
<hibernatetool destdir="${resources.dir}" templatepath="${template.dir}">
<jdbcconfiguration configurationfile="${reveng.dir}hibernate.cfg.xml"
packagename="${package.name}"
revengfile="${reveng.dir}hibernate.reveng.xml"
reversestrategy="${rev.strategy}">
</jdbcconfiguration>
<hbm2hbmxml/>
</hibernatetool>
<hibernatetool destdir="${java.dir}" templatepath="${template.dir}">
<classpath>
<pathelement path="${resources.dir}"/>
<pathelement path="${reveng.resources.dir}"/>
</classpath>
<configuration configurationfile="${reveng.dir}hibernate.cfg.xml"/>
<hbm2java destdir="${java.dir}" templatepath="${template.dir}" jdk5="true"/>
<hbm2ddl
export="false"
update="false"
drop="false"
create="true"
outputfilename="../../.${relative.resources.dir}${generated.schema.dir}hsqldb_schema.sql"
delimiter=";"
format="true"/>
</hibernatetool>
</target>
<target name="updateDB" >
<antcall target="createTables"/>
<antcall target="insertTestData"/>
<antcall target="addConstraints"/>
</target>
</project>
any ideas ? thank you