-->
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: How to use java.lang.Date as an index in a list
PostPosted: Tue Oct 17, 2006 5:24 pm 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
Hi,

I get the folowing exception when trying to use a java.lang.Date as the indexing column for a list. Please find the mapping and exception below. Does anyone have a clue why the type is not recognized and keeps defaulding back to int?

Thank you,
Joost

Hibernate version: 3

Mapping documents:
<list name="employments" lazy="true" inverse="true" cascade="all">
<key>
<column name="userId" />
</key>
<index column="start" type="java.lang.Date" />
<one-to-many class="com.jsportal.projectportal.portalBeans.Employment"/>
</list>

Full stack trace of any exception that occurs:
java.sql.SQLException: Invalid value for getInt() - '2002-01-01' in column 3
at com.mysql.jdbc.ResultSet.getIntFromString(ResultSet.java:2419)
at com.mysql.jdbc.ResultSet.getNativeInt(ResultSet.java:3727)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2338)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2353)
at com.mchange.v2.c3p0.impl.NewProxyResultSet.getInt(NewProxyResultSet.java:2677)
at org.hibernate.type.IntegerType.get(IntegerType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:650)
at org.hibernate.collection.PersistentList.readFrom(PersistentList.java:358)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:994)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:635)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1676)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
at org.hibernate.collection.PersistentList.size(PersistentList.java:91)
at com.jsportal.projectportal.portalBeans.User.getEmployment(User.java:594)
at com.jsportal.projectportal.portalBeans.User.getEmployment(User.java:589)
at com.jsportal.projectportal.portalBeans.User.getCompany(User.java:350)
at com.jsportal.projectportal.web.JSFaces.logon.logon(logon.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
at org.apache.shale.view.faces.ViewActionListener.processAction(ViewActionListener.java:73)
at javax.faces.component.UICommand.broadcast(UICommand.java:106)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.jsportal.projectportal.web.SessionFilter.doFilter(SessionFilter.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.shale.faces.ShaleApplicationFilter.doFilter(ShaleApplicationFilter.java:268)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.jsportal.web.LocaleFilter.doFilter(LocaleFilter.java:149)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)


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

_________________
Joost Schouten
JS Portal


Top
 Profile  
 
 Post subject: type != class (but still help!)
PostPosted: Tue Oct 17, 2006 7:28 pm 
Newbie

Joined: Tue Oct 17, 2006 7:07 pm
Posts: 4
I have a very simple suggestion but it is not a solution as I'm having a very similar problem: in the mapping document "class" and "type" are not the same. The former expects a (fully qualified) classname, where the latter expects a "basic value type". So rather than "java.lang.Date" I think you should have "date" (and you'll have to investigate separately whether that is java.lang.Date or java.sql.Date).

All that said, I'm still having basically the same problem that you are. My column is of hibernate type "timestamp" (java.sql.Timestamp). My map (generated by xdoclet) looks very similar to yours:

Code:
<list name="allEventMedia" lazy="false" cascade="all">
  <key column="event_id"></key>
  <index column="taken_timestamp" type="timestamp"></index>
  <one-to-many class="com.spiralentertainment.model.Media"/>
</list>


I'm using Hibernate version 3.1.3 and a PostgreSQL 8.1.4 database.
Here is the relevant portion of the exception and call stack:

Code:
JDBCExceptionReporter.logExceptions(63) | could not initialize a collection: [com.spiralentertainment.model.Event.allEventMedia#1] [select alleventme0_.event_id as event9_1_, alleventme0_.media_id as media1_1
_, alleventme0_.taken_timestamp as taken10_1_, alleventme0_.media_id as media1_22_0_, alleventme0_.uploader_id as uploader3_22_0_, alleventme0_.mimetype as mimetype22_0_, alleventme0_.path as path22_0_, alleventme0_.suffix as suffix22_0_, alleventme0_.
title as title22_0_, alleventme0_.description as descript8_22_0_, alleventme0_.event_id as event9_22_0_, alleventme0_.taken_timestamp as taken10_22_0_, alleventme0_.type as type22_0_ from media alleventme0_ where alleventme0_.event_id=?]
org.postgresql.util.PSQLException: Bad value for type int : 2006-10-16 15:39:04.805
        at org.postgresql.jdbc2.AbstractJdbc2ResultSet.toInt(AbstractJdbc2ResultSet.java:2515)
        at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:1994)
        at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2208)
        at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:236)
[b]        at org.hibernate.type.IntegerType.get(IntegerType.java:28)
        at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
        at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
        at org.hibernate.persister.collection.AbstractCollectionPersister.readIndex(AbstractCollectionPersister.java:650)[/b]
        at org.hibernate.collection.PersistentList.readFrom(PersistentList.java:358)
        at org.hibernate.loader.Loader.readCollectionElement(Loader.java:994)
        at org.hibernate.loader.Loader.readCollectionElements(Loader.java:635)
        at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:580)
        at org.hibernate.loader.Loader.doQuery(Loader.java:689)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
        at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
        at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)


Last edited by DNewfield on Wed Oct 18, 2006 1:05 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: type="date" did the trick!
PostPosted: Tue Oct 17, 2006 10:52 pm 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
type="date" did the trick!

Thanks,
Joost

_________________
Joost Schouten
JS Portal


Top
 Profile  
 
 Post subject: I was wrong
PostPosted: Wed Oct 18, 2006 12:16 pm 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
Ok, I was tired yesterday and am mistaken as all that happened was that another exception hid the one I was working on. I still have the same problem where it defaults to retreiving an int, in stead of a date.

So still working to find a solution...

Joost

_________________
Joost Schouten
JS Portal


Top
 Profile  
 
 Post subject: Re: How to use java.lang.Date as an index in a list
PostPosted: Wed Oct 18, 2006 12:54 pm 
Newbie

Joined: Wed Oct 18, 2006 11:18 am
Posts: 9
Location: Nanterre, France
Hi guys.

Well, a list index is, by nature, an integral value.
You're trying to stuff it with a temporal value...

May be what you need is a map instead of a list, don't you ?


Top
 Profile  
 
 Post subject: now that is usefull info!
PostPosted: Wed Oct 18, 2006 1:18 pm 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
You seem to be absolutely right. You brought me two log lines futher to my next non hibernate exception!

Thanks,
Joost

_________________
Joost Schouten
JS Portal


Top
 Profile  
 
 Post subject: not list, not map, but ordered bag
PostPosted: Wed Oct 18, 2006 1:34 pm 
Newbie

Joined: Tue Oct 17, 2006 7:07 pm
Posts: 4
I really want a bag, but I want to be able to have the elements of that bag get sorted into a useful order by the DB rather than the JVM. The hibernate bag accepts an "order-by" attribute, but it expects to find the specified column in the wrong table (for my schema, anyway).

-Dale


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.