-->
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.  [ 7 posts ] 
Author Message
 Post subject: hbm2java crashing with generics enabled - with a fix!
PostPosted: Thu Aug 04, 2005 9:58 pm 
Newbie

Joined: Thu Aug 04, 2005 3:06 pm
Posts: 3
Location: Chitizzle
Hi

I am (was) having a weird promblem with the hbm2java ant task. I tried looking for info on the web, but found nothing. I'm a complete newby at Hibernate, so if any of this is old news to people, I appologise.

The problem is that the ant task (hbm2java) was crashing while processing the following snippet:

Code:

<class name="patient" table="patient">
      <id name="patientID" type="int" >
         <generator class="sequence" />
      </id>
      <property name="firstName" type="string" length="64" not-null="true" />
      <property name="lastName" type="string" length="64" not-null="true" />
      <property name="medRecNum" type="string" length="64" not-null="true" />
      <property name="dob" type="date" not-null="true" />
      <property name="heightFt" type="int" not-null="true" />
      <property name="heightIn" type="int" not-null="true" />
      <set name="visits">
         <key column="patientID" />
         <many-to-many column="visitID" unique="true" class="visit" />
      </set>
   </class>
   <class name="visit" table="visit" >
      <id name="visitId" column="visitiId" type="int" >
         <generator class="sequence" />
      </id>
   </class>



It was failing with a class cast exception:

Code:

[hibernatetool] java.lang.ClassCastException: org.hibernate.mapping.ManyToOne
[hibernatetool]         at org.hibernate.tool.hbm2x.Cfg2JavaTool.getRawTypeName(Cfg2JavaTool.java:594)
[hibernatetool]         at org.hibernate.tool.hbm2x.Cfg2JavaTool.getJavaTypeName(Cfg2JavaTool.java:494)
[hibernatetool]         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[hibernatetool]         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)



I tried applying this http://opensource.atlassian.com/projects/hibernate/browse/HBX-224 . No luck. After digging arount the latest CVS checkout of HibernateExt, I narrowed the problem to a block of code at approximately line 600 of Cfg2JavaTool.java. There's a line that's trying to cast a variable to a OneToMany.

Code:
OneToMany oneToMany = (OneToMany) collection.getElement();


At runtime though, the variable is of type ManyToOne. Hence the class cast exception. So what I did was check for the variable type.:

Code:

Object temp = collection.getElement();

                            //OneToMany oneToMany = (OneToMany)temp;

                            String entityName = null;

                            if(temp instanceof ManyToOne)
                            {
                                entityName = ((ManyToOne)temp).getReferencedEntityName();
                            }
                            else if(temp instanceof OneToMany)
                            {
                                entityName = ((OneToMany)temp).getReferencedEntityName();
                            }



So umm.... do I get a cookie? :)

Hopefully this will help someone.

Also, how come the patch for another bug http://opensource.atlassian.com/projects/hibernate/browse/HBX-224 is not in CVS?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 3:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
put a patch in cvs.

why the other bug is not in cvs ? oversight i would assume.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 3:43 pm 
Newbie

Joined: Wed Sep 14, 2005 3:38 pm
Posts: 5
I'm getting this same error. Is the resolution to this problem rolled into any distribution? Or is there an older distribution that supports many-to-many without this problem?

Really didn't want to get into modifying source code. Started out with 3.0.1 with this problem and moved to latest (3.1.0). I'm assuming that this worked at some point, do I have to go back to hibernate2?

thx, Ian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 4:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no and many-to-many support is not a toppriority.....would be good if people that has problems with it supply patches.

peace,

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 4:37 pm 
Newbie

Joined: Wed Sep 14, 2005 3:38 pm
Posts: 5
maybe he assumed that CVS write access was limited to developers. I mis-read your original reply - I thought you said you had put a fix into CVS, didn't realize you were asking him to put one in (maybe he made the same mistake).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 1:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ah - i miswrote...should read: Put a patch in Jira

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 6:22 pm 
Newbie

Joined: Thu Feb 12, 2004 6:19 pm
Posts: 10
For the record, this is not limited to many-to-many mappings. I have no many-to-many mappings and I get the same error -- it also affects many-to-one mappings.


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