-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: <meta attribute="property-type"> not working
PostPosted: Tue Dec 05, 2006 9:46 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 11:58 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Hmm...

Seems to work fine for me. When I add a meta attribute for property-type as byte[], it generated just fine. Can you post your reveng file and the full hbm.xml for the table with the LOGO column? I can't even see anywhere in the code where it would fall back to Serializable for hbm2java. There is a fallback to Serializable during hbm2hbmxml, but only when the jdbc type is unknown. But you would see that in the generated hbm.xml file.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 10:16 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
here is my hibernate.reveng.xml file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>

    <schema-selection match-schema="PUBLIC"/>

    <type-mapping>
        <sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Long" not-null="true"/>
        <sql-type jdbc-type="NUMERIC" hibernate-type="java.lang.Long" not-null="false"/>
        <sql-type jdbc-type="BIGINT" hibernate-type="java.lang.Long" not-null="true"/>
        <sql-type jdbc-type="BIGINT" hibernate-type="java.lang.Long" not-null="false"/>
        <sql-type jdbc-type="TINYINT" hibernate-type="java.lang.Boolean" not-null="true"/>
        <sql-type jdbc-type="TINYINT" hibernate-type="java.lang.Boolean" not-null="false"/>
        <sql-type jdbc-type="DECIMAL" hibernate-type="java.lang.Long" not-null="true"/>
        <sql-type jdbc-type="DECIMAL" hibernate-type="java.lang.Long" not-null="false"/>
        <sql-type jdbc-type="VARCHAR" hibernate-type="java.lang.String"/>
        <sql-type jdbc-type="DATE" hibernate-type="java.util.Date"/>
        <sql-type jdbc-type="BINARY" hibernate-type="org.kobit.ofam.service.dao.hibernate.usertype.BinaryBlobType"/>
    </type-mapping>

    <table-filter match-name="BIN$.*" exclude="true"/>
    <table-filter match-name="CG_REF_CODES" exclude="true"/>
    <table-filter match-name=".*"/>
</hibernate-reverse-engineering>


I have added the meta tab by changing the template... below is the property.hbm.ftl
Code:
    <property
        name="${property.name}"
        type="${property.value.typeName}"
<#if !property.updateable>
        update="false"
</#if>
<#if !property.insertable>
        insert="false"
</#if>
<#if !property.basicPropertyAccessor>
        access="${property.propertyAccessorName}"
</#if>
<#if property.lazy>
        lazy="true"
</#if>
<#if !property.optimisticLocked>
        optimistic-lock="false"
</#if>

<#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>



and below it's the mapping file that I generate...
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Nov 3, 2006 11:02:00 AM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
    <class name="org.kobit.ofam.service.model.Mandant" table="MANDANT" schema="PUBLIC" dynamic-update="true"
           dynamic-insert="true">
        <id name="id" type="java.lang.Long">
            <meta attribute="use-in-equals">true</meta>

            <column name="ID"/>

            <generator class="assigned">
                <param name="sequence">seq_Mandant_id</param>
            </generator>

            <!--    this was removed from the template:
                    <generator class="assigned" />
            -->
        </id>

        <version column="XVERSION" name="xversion" access="property" unsaved-value="null" type="java.lang.Long"/>

        <many-to-one name="adresse" class="org.kobit.ofam.service.model.Adresse" fetch="select">
            <column name="ADRESSE" not-null="true"/>
        </many-to-one>

        <many-to-one name="standort" class="org.kobit.ofam.service.model.Standort" fetch="select">
            <column name="STANDORT" not-null="true"/>
        </many-to-one>

        <property name="bez" type="java.lang.String">
            <column name="BEZ" length="60" not-null="true"/>
        </property>

        <property name="abfallJn" type="java.lang.Boolean">
            <column name="ABFALL_JN" not-null="true"/>
        </property>

        <property name="schrottJn" type="java.lang.Boolean">
            <column name="SCHROTT_JN" not-null="true"/>
        </property>

        <property name="reinigungJn" type="java.lang.Boolean">
            <column name="REINIGUNG_JN" not-null="true"/>
        </property>

        <property name="bewachungJn" type="java.lang.Boolean">
            <column name="BEWACHUNG_JN" not-null="true"/>
        </property>

        <property name="logo" type="org.kobit.ofam.service.dao.hibernate.usertype.BinaryBlobType">
            <column name="LOGO"/>
        </property>

        <property name="bezExtra" type="java.lang.String">
            <column name="BEZ_EXTRA" length="100" not-null="true"/>
        </property>

        <property name="bem" type="java.lang.String">
            <column name="BEM" length="200"/>
        </property>

        <property name="xorder" type="java.lang.Long">
            <column name="XORDER" not-null="true"/>
        </property>

        <property name="xdelJn" type="java.lang.Boolean">
            <column name="XDEL_JN" not-null="true"/>
        </property>

        <property name="xinsertedAt" type="java.util.Date">
            <column name="XINSERTED_AT" length="0" not-null="true"/>
        </property>

        <property name="xinsertedBy" type="java.lang.Long">
            <column name="XINSERTED_BY" not-null="true"/>
        </property>

        <property name="xchangedAt" type="java.util.Date">
            <column name="XCHANGED_AT" length="0"/>
        </property>

        <property name="xchangedBy" type="java.lang.Long">
            <column name="XCHANGED_BY"/>
        </property>

        <set name="kostenstellens" inverse="true" cascade="none">
            <meta attribute="property-type">java.util.Collection</meta>

            <key>
                <column name="MANDANT" not-null="true"/>
            </key>

            <one-to-many class="org.kobit.ofam.service.model.Kostenstellen"/>
        </set>

        <set name="ctrlBenutzerMads" inverse="true" cascade="none">
            <meta attribute="property-type">java.util.Collection</meta>

            <key>
                <column name="MANDANT" not-null="true"/>
            </key>

            <one-to-many class="org.kobit.ofam.service.model.CtrlBenutzerMad"/>
        </set>

        <set name="outputs" inverse="true" cascade="none">
            <meta attribute="property-type">java.util.Collection</meta>

            <key>
                <column name="MANDANT" not-null="true"/>
            </key>

            <one-to-many class="org.kobit.ofam.service.model.Output"/>
        </set>

        <set name="inputs" inverse="true" cascade="none">
            <meta attribute="property-type">java.util.Collection</meta>

            <key>
                <column name="MANDANT" not-null="true"/>
            </key>

            <one-to-many class="org.kobit.ofam.service.model.Input"/>
        </set>

        <set name="behaelters" inverse="true" cascade="none">
            <meta attribute="property-type">java.util.Collection</meta>

            <key>
                <column name="MANDANT" not-null="true"/>
            </key>

            <one-to-many class="org.kobit.ofam.service.model.Behaelter"/>
        </set>

        <set name="nachweises" inverse="true" cascade="none">
            <meta attribute="property-type">java.util.Collection</meta>

            <key>
                <column name="MANDANT" not-null="true"/>
            </key>

            <one-to-many class="org.kobit.ofam.service.model.Nachweis"/>
        </set>

        <set name="abteilungs" inverse="true" cascade="none">
            <meta attribute="property-type">java.util.Collection</meta>

            <key>
                <column name="MANDANT" not-null="true"/>
            </key>

            <one-to-many class="org.kobit.ofam.service.model.Abteilung"/>
        </set>
    </class>
</hibernate-mapping>


so.. any ideas ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 10:56 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Well, it is kind of interesting that your generated mapping file does not have
Code:
<meta attribute="property-type">java.lang.String</meta>
. Is that a misposting or did the template not insert that for the logo field mapping?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 4:26 am 
Beginner
Beginner

Joined: Thu Aug 03, 2006 3:43 am
Posts: 45
well I think I found what the problem was... I have a separate module for reveng and maven should solve the dependancies with the other modules... I erased all the jars for my modules from the local repository and now it seems to work... I think the problem was that hbm2java coldn't find the custom type I made and that's why it didn't work properly...

thank you for your time


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.