-->
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.  [ 10 posts ] 
Author Message
 Post subject: ClassCastException in PropertyFactory when deugging
PostPosted: Fri Mar 03, 2006 11:38 am 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
Hibernate version:
3.1.2
Mapping documents:
Annotations
Full stack trace of any exception that occurs:
Code:
Caused by: java.lang.ClassCastException: org.hibernate.type.StringType
   at org.hibernate.tuple.PropertyFactory.buildVersionProperty(PropertyFactory.java:83)
   at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:157)
   at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
   at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
   at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:215)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
   at de.innosystec.persistence.HibernateSessionFactory.createSessionFactoryIfNeeded(HibernateSessionFactory.java:162)
   at de.innosystec.persistence.HibernateSessionFactory.getSessionFactory(HibernateSessionFactory.java:179)
   at de.innosystec.persistence.HibernateSessionProvider.currentSession(HibernateSessionProvider.java:62)
   at de.innosystec.persistence.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:130)

Name and version of the database you are using:
Oracle 10gR2

When I start my application in debug mode I get the above mentioned ClassCastException. If I start the application normally everything runs fine.

Can the reason be that we use Annotations? I can't find a real reaon for this behaviour. Maybe someone can help me.

Rgds,
Axel

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject: DIFFERENCES
PostPosted: Fri Mar 03, 2006 12:05 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I think version property is supposed to be number like Long or Integer, but I see String type has been mentioned in the trace. Could it be that debug classpath holds some outdated mappings, classes etc. Watch for differences.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Re: DIFFERENCES
PostPosted: Mon Mar 06, 2006 9:16 am 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
kgignatyev wrote:
Could it be that debug classpath holds some outdated mappings, classes etc. Watch for differences.


The classpath for debugging and running the application is identical in Eclipse. But now the exception also occurs when starting the application in normal mode. I don't really understand the exception because all version column in my DB are Integers! Someone knows what to do against this exception?

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject: class
PostPosted: Mon Mar 06, 2006 11:28 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It is about class property, or whatever do you have in the mapping file. The version property should be one of implementations of VersionType, namely IntegerType, LongType, TimestampType, etc.
StringType is not among them.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Re: class
PostPosted: Mon Mar 06, 2006 11:43 am 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
kgignatyev wrote:
It is about class property, or whatever do you have in the mapping file. The version property should be one of implementations of VersionType, namely IntegerType, LongType, TimestampType, etc.
StringType is not among them.


I don't have mapping files, because I use Annotations. It looks like in the example below. What's wrong with this definiton?

Code:
@Version
@Column(name="VERSION", unique=false, nullable=false, insertable=true, updatable=true, precision=8, scale=0)
  public Integer getVersion()
  {
    return this.version;
   }

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject: annotations
PostPosted: Mon Mar 06, 2006 12:05 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I do not use annotations because they feel buggy at this time and therefore could not help you here much, perhaps there is some bug in the annotation because yours looks OK for me
http://www.hibernate.org/hib_docs/annot ... tml#d0e235
Try to remove all the extras from column definition and leave column name only

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Solved
PostPosted: Tue Mar 07, 2006 5:18 am 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
I found a fix for my problem. I just added a Type annotation to my Version column. Now it seems to be fixed and Version is always recognized as Integer column. The annotation now looks like below.

Code:
@Version
@Type(type="java.lang.Integer")
@Column(name="VERSION", unique=false, nullable=false, insertable=false, updatable=false, precision=8, scale=0)
  public Integer getVersion()
  {
    return this.version;
  }

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 2:09 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't reproduce your problem. What I do reproduce though is an insert issue since you column is not insertable and non nullable => when Hibernate inserts it is screwed up.

Why do annotations "feel" buggy?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: feelings
PostPosted: Tue Mar 07, 2006 3:25 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Hard to tell exactly why, as I said that is my feeling caused by reading posts.
Do not use them because our clients do not use Java5 yet :(

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 5:40 pm 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
emmanuel wrote:
I don't reproduce your problem. What I do reproduce though is an insert issue since you column is not insertable and non nullable => when Hibernate inserts it is screwed up.


For me Annotations work well. We're going to use them in a production environment because of the better performance when starting the application. (It's a fat client Swing application).

The version column will be nullable in future. The ClassCastException is hard to reproduce. We had two clients which were running without any problem all the time. Two other clients had the ClassCastException always. It's identical hardware. On my laptop I had the ClassCastException sometimes, but I could not find out what caused it to appear or not. With the Type-annotation the Exception is not thrown any more. So this is the best case we could achieve.

Maybe a hint: Our entity class extends a base class which is annotated with
Code:
@MappedSuperClass


In this base class is the version property. Maybe you can reproduce in such an environment.

_________________
You'll never get a second chance to make a first impression!


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