-->
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: ClassCastException with lazy date/timestamp properties
PostPosted: Mon Feb 14, 2005 11:00 pm 
Newbie

Joined: Mon Feb 14, 2005 10:26 pm
Posts: 2
I've set up a mapping file with a lazy date property (see below). When I try to execute a query that should return objects of this type, however, I get a ClassCastException (see below).

The problem appears to be somewhere around MutableType.java:23:

Code:
return (value==null) ? null : deepCopyNotNull(value);


...which looks like it will call deepCopyNotNull even if the value is a LazyPropertyInitializer. This seems to be fine for ImmutableTypes, but for a MutableType (such as DateType), it ends up trying to cast the LazyPropertyInitializer to a Date (see DateType.java:73):

Code:
return new Date( ( (java.util.Date) value ).getTime() );


Naturally this fails. I've worked around the problem by changing MutableType.java:23 to read as follows:

Code:
if (value == null || value.equals(LazyPropertyInitializer.UNFETCHED_PROPERTY)) return null;
        return deepCopyNotNull(value);


Unfortunately since I only started working with Hibernate two days ago I have no idea if this is even a legitimate problem, let alone the right fix in the right place. If anybody can shed some light on whether this is a legitimate bug (which I doubt) or if there's a change that I can make to my config to get around it I'd appreciate it.

Changes I've already made to my mapping include:
* Changing the type from date to timestamp (didn't work; this is what generated the stack trace below)
* Omitting the type attribute altogether (didn't work)
* Commenting out all of the date properties (worked, but obviously isn't a long-term solution)

Hibernate version:
3.0b4

Mapping documents:
Code:
<hibernate-mapping
   package="com.tribe.om.hibernate">

   <class name="Tribe" proxy="Tribe">
      <id name="id">
         <generator class="uuid.hex"/>
      </id>
        <property name="categoryId" lazy="true" column="category_id"/>
        <property name="name"/>
      <property name="description" lazy="true"/>
        <property name="local" lazy="true"/>
      <property name="membership"/>
        <property name="photoId" column="photo_id"/>
        <property name="city" lazy="true"/>
        <property name="state" lazy="true"/>
        <property name="country" lazy="true"/>
        <property name="matureContent" column="mature_content"/>
        <property name="rss" lazy="true"/>
        <property name="regionId" lazy="true" column="region_id"/>
        <property name="zip" lazy="true"/>
        <property name="isDeleted" column="is_deleted"/>
        <property name="userCreated" column="user_created"/>
        <property name="dateCreated" column="date_created" type="date"/>
        <property name="userModified" lazy="true" column="user_modified"/>
        <property name="dateModified" lazy="true" column="date_modified" type="date"/>
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
UserPlugin u = getDescriptor();
String userGuid = u.getPersonId();
Query allTribeQ = session.createQuery("from Tribe as tribe " +
                    "where tribe.name like 'Tribe%'");
allTribes = allTribeQ.list();


Full stack trace of any exception that occurs:
Here's the most relevant part:
Code:
Caused by: java.lang.ClassCastException
   at org.hibernate.type.TimestampType.deepCopyNotNull(TimestampType.java:63)
   at org.hibernate.type.MutableType.deepCopy(MutableType.java:22)
   at org.hibernate.type.TypeFactory.deepCopy(TypeFactory.java:238)
   at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:150)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:442)
   at org.hibernate.loader.Loader.doQuery(Loader.java:400)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:199)
   at org.hibernate.loader.Loader.doList(Loader.java:1417)
   at org.hibernate.loader.Loader.list(Loader.java:1400)
   at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:876)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:831)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
   at com.tribe.plugin.tribes.Tribes.getAllItems(Tribes.java:106)
   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:324)
   at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:267)
   at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:203)
   ... 66 more


And since you asked for it, here's the whole thing:

Code:
java.lang.Exception: Invocation of method 'getAllItems' in  class com.tribe.plugin.tribes.Tribes threw exception class java.lang.ClassCastException : null template name was plugin/tribes/Admin.vm: line 7:26
   at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:242)
   at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175)
   at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:327)
   at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:51)
   at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:97)
   at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
   at org.apache.velocity.Template.merge(Template.java:256)
   at net.tribe.plugin.PluginProvider.render(PluginProvider.java:360)
   at com.tribe.plugin.TribePluginProvider.render(TribePluginProvider.java:187)
   at com.tribe.plugin.TribePluginProvider.renderAdmin(TribePluginProvider.java:130)
   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:324)
   at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:267)
   at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:203)
   at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175)
   at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:220)
   at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
   at org.apache.velocity.Template.merge(Template.java:256)
   at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:449)
   at org.apache.velocity.app.Velocity.mergeTemplate(Velocity.java:418)
   at org.apache.turbine.services.velocity.TurbineVelocityService.executeRequest(TurbineVelocityService.java:415)
   at org.apache.turbine.services.velocity.TurbineVelocityService.handleRequest(TurbineVelocityService.java:281)
   at org.apache.turbine.services.velocity.TurbineVelocity.handleRequest(TurbineVelocity.java:71)
   at org.apache.turbine.modules.screens.VelocityScreen.buildTemplate(VelocityScreen.java:119)
   at org.apache.turbine.modules.screens.TemplateScreen.doBuild(TemplateScreen.java:101)
   at org.apache.turbine.modules.Screen.build(Screen.java:57)
   at org.apache.turbine.modules.ScreenLoader.eval(ScreenLoader.java:104)
   at org.apache.turbine.modules.layouts.VelocityOnlyLayout.doBuild(VelocityOnlyLayout.java:92)
   at org.apache.turbine.modules.Layout.build(Layout.java:53)
   at org.apache.turbine.modules.LayoutLoader.exec(LayoutLoader.java:98)
   at org.apache.turbine.modules.pages.DefaultPage.doBuild(DefaultPage.java:146)
   at org.apache.turbine.modules.Page.build(Page.java:53)
   at org.apache.turbine.modules.PageLoader.exec(PageLoader.java:98)
   at org.apache.turbine.Turbine.doGet(Turbine.java:752)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:307)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.ClassCastException
   at org.hibernate.type.TimestampType.deepCopyNotNull(TimestampType.java:63)
   at org.hibernate.type.MutableType.deepCopy(MutableType.java:22)
   at org.hibernate.type.TypeFactory.deepCopy(TypeFactory.java:238)
   at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:150)
   at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:442)
   at org.hibernate.loader.Loader.doQuery(Loader.java:400)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:199)
   at org.hibernate.loader.Loader.doList(Loader.java:1417)
   at org.hibernate.loader.Loader.list(Loader.java:1400)
   at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:876)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:831)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
   at com.tribe.plugin.tribes.Tribes.getAllItems(Tribes.java:106)
   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:324)
   at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:267)
   at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:203)
   ... 66 more

Name and version of the database you are using:
MySQL 4.0.16

The generated SQL (show_sql=true):
Sorry, I don't have this handy. I did look at the SQL in the debugger, however, and ran the same stuff in my sql client and it looked & worked fine.

Debug level Hibernate log excerpt:
Sorry, I don't have this right now.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 2:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Thanks, this is now fixed in CVS, and a test added.

(This is why we do betas!)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 2:35 am 
Newbie

Joined: Mon Feb 14, 2005 10:26 pm
Posts: 2
Many thanks - very quick turnaround!


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.