-->
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.  [ 3 posts ] 
Author Message
 Post subject: SessionFactory creation failed : VersionType cast exception
PostPosted: Tue Feb 08, 2011 6:59 pm 
Newbie

Joined: Mon Jan 31, 2011 2:49 pm
Posts: 3
Initial SessionFactory creation failed.java.lang.ClassCastException: org.hibernate.type.BigDecimalType cannot be cast to org.hibernate.type.VersionType

For the above exception, I understand the problem and it is that one of the reverse engineered DB Table contains "version" as a field name.
I can fix this by fixing the .hbm.xml, by changing the <version> .... </version> to <property> .... </property>

But I was wondering if someone know how to fix this issue
IF I what if I DON"T want to use the hbm.xml and directly use the
SessionFactory sf = new AnnotatedConfiguration
.configure()
.addPackage("Pkgname")
.addAnnotatedClass("tablewithversionasfield.class")
.buildSessionFactory()

I am not sure how to resolve this error WITHOUT FIXING the hbm.xml file workaround. I cannot change the DB table field and I have to fix it in the hibernate auto generated code. Please advise. Thanks.


Top
 Profile  
 
 Post subject: Re: SessionFactory creation failed : VersionType cast exception
PostPosted: Tue Feb 08, 2011 7:38 pm 
Newbie

Joined: Wed Jan 26, 2011 12:32 pm
Posts: 12
Can you try by using annotations


Top
 Profile  
 
 Post subject: Re: SessionFactory creation failed : VersionType cast exception
PostPosted: Wed Feb 09, 2011 10:49 am 
Newbie

Joined: Mon Jan 31, 2011 2:49 pm
Posts: 3
Hi

I have already used annotation for the reverese engineering and also used the addAnnotatedClass to add the generated class to the session factory. A simple scenario in which this failure can be reproduced is to have the following:
1. Have a SQL table with version field in it as an integer type.
2. Then use the hibernator reverse engineering tool to reverse engineer the table and get a beans out (with annotations).
3. Inside the annotated Beans, you should see a method called getVersion() (and I think it conflicts with some other getVersion used internally by hibernate which seems to expect a VersionType).

4. Similarly, if you generate a .hbm.xml from the same reverse engineering process you will see the xml for this field"version" in the table marked with <version> ... <\version> instead of <property> .... </property>. The only way I have found so far to fix the problem is to open this file and change the version to property and then create the sessionFactory by using the hbm.xml.


If I use the addAnnotatedClass option, I cannot do this fix by myself and it doesn't work and throws the cast exception. Hence my question.


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