-->
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: upgrade from 3.5.6 to 3.6.4 creates class cast exception
PostPosted: Wed Jun 08, 2011 11:37 am 
Newbie

Joined: Wed Jun 08, 2011 11:12 am
Posts: 4
Hello, I am attempting to upgrade hibernate from 3.5.6 to 3.6.4. When I switch to any version higher than 3.5.6 I receive numerous class cast errors from java.lang.String to java.util.Locale. does anyone know if there was a change between the two versions that would cause this?

here are the specifics of where I get the error and the back trace:

backtrace:

Code:
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Locale
   at org.hibernate.type.descriptor.java.LocaleTypeDescriptor.unwrap(LocaleTypeDescriptor.java:1)
   at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$1.doBind(VarcharTypeDescriptor.java:52)
   at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:91)
   at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:282)
   at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277)
   at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1873)
   at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1844)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1716)
   at org.hibernate.loader.Loader.doQuery(Loader.java:801)
   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.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
   at org.openmrs.api.db.hibernate.HibernateConceptDAO.getConcepts(HibernateConceptDAO.java:557)
   at org.openmrs.api.impl.ConceptServiceImpl.getConcepts(ConceptServiceImpl.java:574)
   at org.openmrs.api.impl.ConceptServiceImpl.getConceptsByName(ConceptServiceImpl.java:409)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy35.getConceptsByName(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.openmrs.aop.LoggingAdvice.invoke(LoggingAdvice.java:122)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy36.getConceptsByName(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy36.getConceptsByName(Unknown Source)
   at org.openmrs.validator.ConceptValidator.validate(ConceptValidator.java:158)
   at org.openmrs.validator.ConceptValidatorTest.validate_shouldPassIfTheConceptIsBeingUpdatedWithNoNameChange(ConceptValidatorTest.java:56)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
   at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
   at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
   at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
   at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
   at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
   at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
   at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
   at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)



The call to criteria.list() is from the following method in the DAO:

Code:
public List<Concept> getConcepts(String name, Locale loc, boolean searchOnPhrase, List<ConceptClass> classes,
           List<ConceptDatatype> datatypes) throws DAOException {
      
      Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Concept.class);
      
      criteria.add(Restrictions.eq("retired", false));
      
      if (name != null) {
         if (loc == null)
            throw new DAOException("Locale must be not null");
         criteria.createAlias("names", "names");
         MatchMode matchmode = MatchMode.EXACT;
         if (searchOnPhrase)
            matchmode = MatchMode.ANYWHERE;
         
         criteria.add(Restrictions.ilike("names.name", name, matchmode));
         
         String language = loc.getLanguage();
         if (language.length() > 2) {
            // if searching in specific locale like en_US
            criteria.add(Restrictions.or(Restrictions.eq("names.locale", loc.getLanguage()), Restrictions.eq(
                "names.locale", loc.getLanguage().substring(0, 2))));
         } else {
            // if searching in general locale like just "en"
            criteria.add(Restrictions.like("names.locale", loc.getLanguage(), MatchMode.START));
         }
      }
      
      if (classes.size() > 0)
         criteria.add(Restrictions.in("conceptClass", classes));
      
      if (datatypes.size() > 0)
         criteria.add(Restrictions.in("datatype", datatypes));
      return List = criteria.list();
   }


Any ideas as to how I might go about fixing this?


Top
 Profile  
 
 Post subject: Re: upgrade from 3.5.6 to 3.6.4 creates class cast exception
PostPosted: Wed Jun 15, 2011 12:23 pm 
Newbie

Joined: Tue Sep 25, 2007 6:30 am
Posts: 10
Same here, any help?


Top
 Profile  
 
 Post subject: Re: upgrade from 3.5.6 to 3.6.4 creates class cast exception
PostPosted: Wed Jun 15, 2011 12:27 pm 
Newbie

Joined: Wed Jun 08, 2011 11:12 am
Posts: 4
I have narrowed it down to a problem with the restrictions created with this part of the code:

Code:
criteria.add(Restrictions.like("names.locale", loc.getLanguage(), MatchMode.START));

So what is happening (I think) is that names.locale has type Local, but loc.getLanguage() is a String, so when it tries to compare, things blow up?
I don't know what changed though, because this same called worked fine in 3.5.x.


Top
 Profile  
 
 Post subject: Re: upgrade from 3.5.6 to 3.6.4 creates class cast exception
PostPosted: Wed Jun 15, 2011 1:07 pm 
Newbie

Joined: Tue Sep 25, 2007 6:30 am
Posts: 10
I think you're on the good way.
I fixed my problem.

I had a hql query with "... and locale=?" followed by a :
Code:
Object[] params = { value, locale.toString() };
List<MyEntity> entities = getHibernateTemplate().find(query, params);


I removed the toString(), passing the local "as is" as a param, and it works fine. Looks better this way, i think, so i understand the change. But a documentation in the migration guides could have been useful :)

I think you should try passing "loc" and not "loc.getLanguage", and see how it helps.


Top
 Profile  
 
 Post subject: Re: upgrade from 3.5.6 to 3.6.4 creates class cast exception
PostPosted: Wed Jun 15, 2011 1:39 pm 
Newbie

Joined: Wed Jun 08, 2011 11:12 am
Posts: 4
I would have just passed the loc, but unless I am mistaken, Restrictions with the matchmode requires a String as the second argument. I could be wrong though.


Top
 Profile  
 
 Post subject: Re: upgrade from 3.5.6 to 3.6.4 creates class cast exception
PostPosted: Thu Jun 16, 2011 2:09 am 
Newbie

Joined: Thu Jun 16, 2011 1:58 am
Posts: 1
Location: california
hi czakian,Your information is good.Thanks for sharing.

_________________
Medical Marijuana Clinic | Medical Cannabis Card California


Top
 Profile  
 
 Post subject: Re: upgrade from 3.5.6 to 3.6.4 creates class cast exception
PostPosted: Thu Jun 16, 2011 3:12 am 
Newbie

Joined: Tue Sep 25, 2007 6:30 am
Posts: 10
Restriction.eq does take an object as the value to restrict on. I don't think it has to be a String.


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.