-->
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: CharacterTypeDescriptor throws StringIndexOutOfBoundsExcepti
PostPosted: Wed Dec 08, 2010 10:07 am 
Newbie

Joined: Thu Jan 24, 2008 4:45 am
Posts: 13
I'm using hibernate 3.6.0. org.hibernate.type.descriptor.java.CharacterTypeDescriptor throws StringIndexOutOfBoundsException.

Maybe

Code:
78      if ( String.class.isInstance( value ) ) {
79         final String str = (String) value;
80         return Character.valueOf( str.charAt(0) );
81      }


should be replaced with:

Code:
      if ( String.class.isInstance( value ) ) {
         final String str = (String) value;
         if ( str.length() == 0 ) {
            return null;
         }
         return Character.valueOf( str.charAt(0) );
      }



Here is the current stacktrace:

Code:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
   at java.lang.String.charAt(String.java:686)
   at org.hibernate.type.descriptor.java.CharacterTypeDescriptor.wrap(CharacterTypeDescriptor.java:80)
   at org.hibernate.type.descriptor.java.CharacterTypeDescriptor.wrap(CharacterTypeDescriptor.java:34)
   at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$2.doExtract(VarcharTypeDescriptor.java:61)
   at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
   at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
   at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:249)
   at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:229)
   at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:330)
   at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2265)
   at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1527)
   at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1455)
   at org.hibernate.loader.Loader.getRow(Loader.java:1355)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:611)
   at org.hibernate.loader.Loader.doQuery(Loader.java:829)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
   at org.hibernate.loader.Loader.doList(Loader.java:2533)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
   at org.hibernate.loader.Loader.list(Loader.java:2271)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246)
   at org.hibernate.ejb.criteria.CriteriaQueryCompiler$3.getResultList(CriteriaQueryCompiler.java:260)


Last edited by sslavic on Wed Dec 08, 2010 11:04 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: CharacterTypeDescriptor throws StringIndexOutOfBoundsExcepti
PostPosted: Wed Dec 08, 2010 10:15 am 
Newbie

Joined: Thu Jan 24, 2008 4:45 am
Posts: 13
fromString method in same class might have similar issue to the one in unwrap method.


Top
 Profile  
 
 Post subject: Re: CharacterTypeDescriptor throws StringIndexOutOfBoundsExcepti
PostPosted: Wed Dec 08, 2010 11:04 am 
Newbie

Joined: Thu Jan 24, 2008 4:45 am
Posts: 13
To give you context, reverse engineering legacy database using Hibernate Tools recognized a column as Character, and when I tried to read data from legacy database Hibernate threw this exception for a row where this Character column/field had value of "" (empty string). Yes, that legacy database is corrupt. Changed field type to String, and Hibernate reads data well.

If not changing CharacterTypeDescriptor to handle gracefully empty strings, than at least wrap should be changed to throw HibernateException if string length is != 1, just like fromString throws it for the same condition.


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.