-->
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.  [ 15 posts ] 
Author Message
 Post subject: ClassCastException using hbm2java.CodeGenerator with meta
PostPosted: Sat Oct 18, 2003 11:04 am 
Newbie

Joined: Sat Oct 18, 2003 10:44 am
Posts: 3
Location: Orange County, CA
When using net.sf.hibernate.tool.hbm2java.CodeGenerator, if I use any meta tags in the mapping file, I get a ClassCastException when running the codegen. If I comment out all meta tags, it works fine.

I'm using v2.0.3 of the hibernate.jar and v2.1 of the hibernate tools.

It seemed I had to build the hibernate-tools.jar locally to get the hbm2java class in the hibernate-tools.jar. Maybe this is my problem??

Is there a version of the hibernate-tools.jar that includes the hmb2java?
Thanks in advance for any help...

Here's the mapping with a single meta tag UNcommented:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>


   <meta attribute="extends">com.medengineering.bus.vo.HibernateVOImpl</meta>
   <!--meta attribute="implements">com.medengineering.bus.vo.HibernateVO</meta-->
   <class name="com.medengineering.bus.vo.CatalogItemVO"
        table="catalog_item">
      <!--meta attribute="class-description">
         Items for the catalog
         @author jay
      </meta-->
      <id name="id" type="long">
         <generator class="increment"/>
      </id>
      <property name="catalogItemName" type="string">
         <!--meta attribute="field-description">
            The item's name as will be displayed in search results etc.
         </meta-->
      </property>
      <property name="descLong" type="string">
         <!--meta attribute="field-description">Long description. May contain HTML.</meta-->
      </property>
      <many-to-one name="category" column="category_id"
               class="com.medengineering.bus.vo.CatalogCategoryVO">
      </many-to-one>
      <set name="images" inverse="true">
         <key column="catalog_item_id"/>
         <one-to-many class="com.medengineering.bus.vo.CatalogImageVO"/>
      </set>
   </class>

   <class name="com.medengineering.bus.vo.CatalogCategoryVO"
         table="catalog_category">
      <!--meta attribute="class-description">Category</meta-->
      <id name="id" type="long">
         <generator class="increment"/>
      </id>
      <property name="categoryName" type="string">
         <!--meta attribute="field-description">short category name</meta-->
      </property>
      <property name="parentId" type="java.lang.Long" column="parent_id" insert="false" update="false"/>
      <set name="catalogItems" inverse="true">
         <key column="category_id"/>
         <one-to-many class="com.medengineering.bus.vo.CatalogItemVO"/>
      </set>
      <set name="subCategories" inverse="true" >
         <key column="parent_id"/>
         <one-to-many class="com.medengineering.bus.vo.CatalogCategoryVO"/>
      </set>

      <many-to-one  name="parentCategory" column="parent_id" class="com.medengineering.bus.vo.CatalogCategoryVO" >

      </many-to-one>

   </class>

   <class name="com.medengineering.bus.vo.CatalogImageVO"
        table="catalog_image">
      <id name="id" type="long">
         <!--meta attribute="scope-set">
            protected
         </meta-->
         <generator class="increment"/>
      </id>
      <property name="imageType" type="int"/>
      <property name="description" type="string">
         <!--meta attribute="field-description">
            Some description of the image
         </meta-->
      </property>
      <property name="imagedata" type="blob"/>
      <many-to-one name="parentItem" column="catalog_item_id" class="com.medengineering.bus.vo.CatalogItemVO"/>
   </class>
</hibernate-mapping>

Here's the stack trace:
Code:
java.lang.ClassCastException
   at net.sf.hibernate.tool.hbm2java.MetaAttributeHelper.mergeMetaMaps(MetaAttributeHelper.java:89)
   at net.sf.hibernate.tool.hbm2java.MetaAttributeHelper.loadAndMergeMetaMap(MetaAttributeHelper.java:110)
   at net.sf.hibernate.tool.hbm2java.ClassMapping.initWith(ClassMapping.java:86)
   at net.sf.hibernate.tool.hbm2java.ClassMapping.<init>(ClassMapping.java:73)
   at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:99)


Here's the ant target:
Code:
<target name="codegen-catalog" description="generate the VO code for the catalog">
      <java classname="net.sf.hibernate.tool.hbm2java.CodeGenerator"
             fork="true"
             failonerror="true">
         <classpath>
            <path refid="base.path"/>
         </classpath>
         <arg value="--output=${src.java}"/>
         <arg value="${conf.dir}/hibernate-catalog-map.hbm.xml"/>

      </java>
   </target>


Top
 Profile  
 
 Post subject: found a binary hibernate-tools.jar - still same problem...
PostPosted: Sat Oct 18, 2003 12:58 pm 
Newbie

Joined: Sat Oct 18, 2003 10:44 am
Posts: 3
Location: Orange County, CA
eom


Top
 Profile  
 
 Post subject: same problem - ClassCastException with hbm2java and meta tag
PostPosted: Sat Mar 20, 2004 8:24 am 
Newbie

Joined: Sat Mar 20, 2004 7:43 am
Posts: 4
Location: Sydney, Australia
Hi,

I'm having the same issue with hibernate 2.1 and hibernate extensions 2.0.2. I have also built the cvs HEAD revision of hibernate-extensions and the error occurs in that version too. I am processing the hbm files generated using MiddleGen through ant and receive the following exception, (note the line numbers are slightly different in the cvs version, but it's the same exception):

Code:
[hbm2java] java.lang.ClassCastException
[hbm2java]     at net.sf.hibernate.tool.hbm2java.MetaAttributeHelper.mergeMetaMaps(MetaAttributeHelper.java:89)
[hbm2java]     at net.sf.hibernate.tool.hbm2java.MetaAttributeHelper.loadAndMergeMetaMap(MetaAttributeHelper.java:110)
[hbm2java]     at net.sf.hibernate.tool.hbm2java.ClassMapping.initWith(ClassMapping.java:160)
[hbm2java]     at net.sf.hibernate.tool.hbm2java.ClassMapping.<init>(ClassMapping.java:72)
[hbm2java]     at net.sf.hibernate.tool.hbm2java.CodeGenerator.handleClass(CodeGenerator.java:128)
[hbm2java]     at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:103)
[hbm2java]     at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.processFile(Hbm2JavaTask.java:145)
[hbm2java]     at net.sf.hibernate.tool.hbm2java.Hbm2JavaTask.execute(Hbm2JavaTask.java:95)
[hbm2java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:306)
[hbm2java]     at org.apache.tools.ant.Task.perform(Task.java:401)
[hbm2java]     at org.apache.tools.ant.Target.execute(Target.java:338)
[hbm2java]     at org.apache.tools.ant.Target.performTasks(Target.java:365)
[hbm2java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1237)
[hbm2java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1094)
[hbm2java]     at org.apache.tools.ant.Main.runBuild(Main.java:669)
[hbm2java]     at org.apache.tools.ant.Main.startAnt(Main.java:220)
[hbm2java]     at org.apache.tools.ant.Main.start(Main.java:184)
[hbm2java]     at org.apache.tools.ant.Main.main(Main.java:267)


Here is an example of a hbm file that validates against the dtd and works fine if I comment out the meta tags:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="jonnydee.nextgemeration.persistence.hibernate.Location"
    table="location"
>
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="location"
    </meta>

    <id
        name="locationid"
        type="java.lang.Long"
        column="locationid"
    >
        <meta attribute="field-description">
           @hibernate.id
            generator-class="assigned"
            type="java.lang.Long"
            column="locationid"

        </meta>
        <generator class="assigned" />
    </id>

    <property
        name="name"
        type="java.lang.String"
        column="name"
        not-null="true"
        length="64"
    >
        <meta attribute="field-description">
           @hibernate.property
            column="name"
            length="64"
            not-null="true"
        </meta>   
    </property>
    <property
        name="sortorder"
        type="int"
        column="sortorder"
        not-null="true"
        length="4"
    >
        <meta attribute="field-description">
           @hibernate.property
            column="sortorder"
            length="4"
            not-null="true"
        </meta>   
    </property>
    <property
        name="version"
        type="long"
        column="version"
        not-null="true"
        length="8"
    >
        <meta attribute="field-description">
           @hibernate.property
            column="version"
            length="8"
            not-null="true"
        </meta>   
    </property>

    <!-- associations -->
    <!-- bi-directional one-to-many association to Costcentrelocation -->
    <set
        name="costcentrelocations"
        lazy="true"
        inverse="true"
    >
        <meta attribute="field-description">
           @hibernate.set
            lazy="true"
            inverse="true"

          @hibernate.collection-key
           column="locationid"

           @hibernate.collection-one-to-many
            class="jonnydee.nextgemeration.persistence.hibernate.Costcentrelocation"
        </meta>
        <key>
            <column name="locationid" />
        </key>
        <one-to-many
            class="jonnydee.nextgemeration.persistence.hibernate.Costcentrelocation"
        />
    </set>
    <!-- bi-directional one-to-many association to Employee -->
    <set
        name="employees"
        lazy="true"
        inverse="true"
    >
        <meta attribute="field-description">
           @hibernate.set
            lazy="true"
            inverse="true"

          @hibernate.collection-key
           column="locationid"

           @hibernate.collection-one-to-many
            class="jonnydee.nextgemeration.persistence.hibernate.Employee"
        </meta>
        <key>
            <column name="locationid" />
        </key>
        <one-to-many
            class="jonnydee.nextgemeration.persistence.hibernate.Employee"
        />
    </set>
    <!-- bi-directional one-to-many association to Rolerelationshipmanager -->
    <set
        name="rolerelationshipmanagers"
        lazy="true"
        inverse="true"
    >
        <meta attribute="field-description">
           @hibernate.set
            lazy="true"
            inverse="true"

          @hibernate.collection-key
           column="locationid"

           @hibernate.collection-one-to-many
            class="jonnydee.nextgemeration.persistence.hibernate.Rolerelationshipmanager"
        </meta>
        <key>
            <column name="locationid" />
        </key>
        <one-to-many
            class="jonnydee.nextgemeration.persistence.hibernate.Rolerelationshipmanager"
        />
    </set>

</class>
</hibernate-mapping>


Anyone else seen this problem or have any ideas? As far as I can tell from the cvs HEAD revision source, there is a problem with this cast at line 91 in net.sf.hibernate.tool.hbm2java.MetaAttributeHelper:

Code:
MetaAttribute element = (MetaAttribute) iterator.next();


Thanks in advance for any assistance.

Jon


Top
 Profile  
 
 Post subject: Hacky workaround for hbm2java meta tag problem
PostPosted: Sat Mar 20, 2004 9:28 pm 
Newbie

Joined: Sat Mar 20, 2004 7:43 am
Posts: 4
Location: Sydney, Australia
I've delved a bit further into this problem and it is caused by the MetaAttributeHelper being passed an ArrayList when it is expecting a MetaAttribute, hence the ClassCastException. I've added an extremely hacky workaround by modifying the MetaAttributeHelper line 91 as follows:

Code:
MetaAttribute element = (MetaAttribute)((ArrayList)iterator.next()).get(0);


This just extracts the first element from the ArrayList and uses that. Really this is only a workaround as the ArrayList shouldn't be passed in here, but it works for me. Luckily, all of the ArrayLists passed in for my classes only contain one element. Obviously this won't work if that isn't the case. After this change, hbm2java successfully finishes and the classes have the XDoclet tags in place :)

Regards,

Jon


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 21, 2004 12:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
are you 100% sure that you have get this behavior when running from the head cvs version of hibernate-extensions ?

if yes - then submit a bug on it with a SIMPLE mapping file...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Bug logged
PostPosted: Mon Mar 22, 2004 4:09 am 
Newbie

Joined: Sat Mar 20, 2004 7:43 am
Posts: 4
Location: Sydney, Australia
I've logged the bug with a simple test case. Issue number HB-829.

Cheers,

Jon


Top
 Profile  
 
 Post subject: Re: Bug logged
PostPosted: Mon Mar 22, 2004 4:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
jdenly wrote:
I've logged the bug with a simple test case. Issue number HB-829.

Cheers,

Jon


yes - and i have now closed as a "cannot reproduce" since the problem ain't in the current cvs as i said !

Please check that the next time - ok ? ;)

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Sorry - my mistake!
PostPosted: Mon Mar 22, 2004 6:08 pm 
Newbie

Joined: Sat Mar 20, 2004 7:43 am
Posts: 4
Location: Sydney, Australia
I checked out from CVS the top level directory marked as HibernateExt - I guess that must be a link to the release version, not the current HEAD. Sorry to waste your time with something you've already fixed! Thanks for your efforts on this.

(Embarressed) regards,

Jon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 12:44 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 6:52 am
Posts: 46
So I'm a bit confused - I'm getting the same error with a
_really_ simple mapping file and hibernate-exetensions 2.0.2.

Is it a known problem in hibernate-extensions-2.0.2, but it's
been fixed in the CVS? If so, does that mean I need to
build the latest from CVS, or is there a release soon, or...?

Thanks,

Hunter


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 1:14 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 6:52 am
Posts: 46
Sorry to reply to my own post, but I've tried to build
hibernate extensions from CVS, and I still get the error.

I've tried explicitly checking out with -r HEAD, and still get the same
thing. I've noticed that the build still produces directories with
2.0.1 in them, though.

which branch do I need to build from to get a working version?

it looks like v22branch version of MetaAttributeHelper.java is even older...

H


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 1:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it is HEAD and i used the hbm.xml file that you had in the jira.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: I've found the culprit!!
PostPosted: Tue Mar 23, 2004 2:13 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 6:52 am
Posts: 46
Actually, I'm a different person having the same problem :)

It's the latest cvs version (checked out with -r HEAD).

The strange thing is that this works fine in another project,
so I copied over the simplified mapping file, and the mapping file
and code generation work in the other project.

I've done a bit of digging/fiddling, and I've narrowed it down
to the fact that the new project is using the latest copy
of jakarta-commons-collections, version 3.0, which I gather
is a pretty signifigant change.

I haven't looked at the latest source for 3.0, and I won't have time
till tomorrow (it's quitting time here :).

I guess the big question is whether or not hibernate-tools should
support the use of jakarta-commons-collections 3.0?

Hunter


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 2:17 pm 
Beginner
Beginner

Joined: Mon Sep 08, 2003 6:52 am
Posts: 46
Here's the simplified mapping file I use:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

  <class name="com.newbay.mixxe.domain.User" table="users" dynamic-update="true" lazy="true">

    <meta attribute="generated-class">UserVO</meta>
   
    <id name="id" type="int" unsaved-value="0" >
      <generator class="native"/>
    </id>

    <property name="userName" not-null="true" type="string" unique="true"/>
    <property name="password" not-null="true" type="string"/>
  </class>

</hibernate-mapping>

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 6:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so you are using another library than the one in the distribution ? and especially a library which haven't been released yet ? ;)

so - if i'm going to fix that someone has to tell me what has changed between the two multimap implementations since they don't behave the same ? is it fixable by just casting to List instead of ArrayList ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 24, 2004 6:02 am 
Beginner
Beginner

Joined: Mon Sep 08, 2003 6:52 am
Posts: 46
Well, commons-collections doesn't ship with hibernate tools at all,
and it was officially released two months ago :)

Anyway, I'm gonna try and track down the problem, and see if it is
an easy fix. I'll create a new topic for the follow up.

H


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 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.