-->
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.  [ 8 posts ] 
Author Message
 Post subject: ClassCastException when loading boolean from SqlServer
PostPosted: Fri Oct 14, 2005 1:22 pm 
Newbie

Joined: Tue May 25, 2004 9:56 am
Posts: 19
Hibernate 3.1beta3
Hibernate Annotations 3.1beta5
SQLServerDialect

I have this code (getService() essentially delegates to a hibernate Session):
Code:
SupportListItem item = getService().getObjectById(id, SupportListItem.class);
item.setEnabled(false);  // AdminSupport.java:80, where the error happens
getService().saveOrUpdate(item);

which uses this class:

Code:
@Entity(access = AccessType.FIELD)
public class SupportListItem {
   @Id(generate = GeneratorType.AUTO)
   protected long id;
   protected boolean enabled = true;
   ...

   public boolean isEnabled() {
      return enabled;
   }

   public void setEnabled(boolean enabled) {
      this.enabled = enabled;
   }
   ...
}


and I get this exception:

Code:
Caused by: java.lang.ClassCastException: java.lang.Integer
   at org.hibernate.type.LongType.set(LongType.java:42)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:63)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:45)
   at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
   at org.hibernate.loader.Loader.doQuery(Loader.java:661)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1782)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
   at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
   at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2712)
   at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
   at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
   at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
   at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:82)
   at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:781)
   at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:743)
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:62)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
   at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
   at edu.cornerstone.portal.portlet.forms.model.SupportListItem$$EnhancerByCGLIB$$4e828907.setEnabled(<generated>)
   at edu.cornerstone.portal.portlet.forms.bean.AdminSupport.doDelete(AdminSupport.java:80)
   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:585)
   at com.sun.el.parser.AstValue.invoke(AstValue.java:130)
   at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
   at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
   at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
   ... 52 more




Is this a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 1:32 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
your getting CCE from item.setEnabled(false); ?

somewhere you are handing H an Integer but it should be a Long.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 2:04 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
I do not think it has anything to do with
item.setEnabled(false);

I bet there is something incorrect in your mapping file. It is very likely you are mapping your id field as java.lang.Integer, but the id field in your class is long type.

Hope this is helpful.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 2:20 pm 
Newbie

Joined: Tue May 25, 2004 9:56 am
Posts: 19
I am using Hibernate Annotations so there is no explicit mapping for that field. Annotations automatically maps basic data types to columns. And in that is the problem... I think.[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 2:44 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
what is going on in edu.cornerstone.portal.portlet.forms.bean.AdminSupport.doDelete ? again, somewhere there is an integer where there needs of be a long.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 2:51 pm 
Newbie

Joined: Tue May 25, 2004 9:56 am
Posts: 19
Please look at the stack trace more carefully. These lines indicate it is with the boolean field "enabled". AdminSupport.java line 80 is item.setEnabled(false);

Code:
   at edu.cornerstone.portal.portlet.forms.model.SupportListItem$$EnhancerByCGLIB$$4e828907.setEnabled(<generated>)
   at edu.cornerstone.portal.portlet.forms.bean.AdminSupport.doDelete(AdminSupport.java:80)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 2:54 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
brondsem wrote:
Please look at the stack trace more carefully. These lines indicate it is with the boolean field "enabled". AdminSupport.java line 80 is item.setEnabled(false);

Code:
   at edu.cornerstone.portal.portlet.forms.model.SupportListItem$$EnhancerByCGLIB$$4e828907.setEnabled(<generated>)
   at edu.cornerstone.portal.portlet.forms.bean.AdminSupport.doDelete(AdminSupport.java:80)


And these lines indicate that you're trying to use an Integer to populate a Long field.

Code:
Caused by: java.lang.ClassCastException: java.lang.Integer
   at org.hibernate.type.LongType.set(LongType.java:42)

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 3:06 pm 
Newbie

Joined: Tue May 25, 2004 9:56 am
Posts: 19
Ok, perhaps I was too hasty :-) I load my object by using an int "id" but the "id" field is a long. That's probably it.

Unfortunately there's a power outage on the campus this afternoon and I won't be able to test this until Monday since all the servers are going down.


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