-->
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.  [ 4 posts ] 
Author Message
 Post subject: cannot perform lookups on timestamps
PostPosted: Sat Mar 19, 2005 8:51 pm 
Newbie

Joined: Wed Mar 09, 2005 12:54 pm
Posts: 5
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

3.0

Mapping documents:

<hibernate-mapping package="com.wiag.hdb.model">

<class name="LieferPunktGruppeInfo" table="A10T_LFPGRP_INF">
<composite-id name="id" class="LieferPunktGruppeInfoKey">
<key-property name="lieferPunktGruppeID" column="LFPGRP_LFPGRP" type="java.lang.Long"/>
<key-property name="vertragID" column="LFPGRP_ZO_ID" type="java.lang.Long"/>
<key-property name="typ" column="TYP" type="java.lang.Integer"/>
<key-property name="von" column="VON" type="java.util.Date"/>
<key-property name="za" column="ZA" type="java.lang.Integer"/>
</composite-id>

<timestamp name="aendZm" column="AEND_ZM"/>
<property name="bis" column="BIS" type="java.util.Date" />
<property name="wert" column="WERT" type="java.lang.Long" not-null="true" />
<property name="wertEh" column="WERT_EH" type="java.lang.Long" not-null="true" />
<property name="aendId" column="AEND_ID" type="java.lang.Long" />

</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

java.lang.UnsupportedOperationException: cannot perform lookups on timestamps
at org.hibernate.type.TimestampType.getHashCode(TimestampType.java:99)
at org.hibernate.type.AbstractType.getHashCode(AbstractType.java:119)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:162)
at org.hibernate.engine.EntityKey.getHashCode(EntityKey.java:68)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:41)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:664)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:277)
at org.hibernate.loader.Loader.doQuery(Loader.java:384)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1344)
at org.hibernate.loader.collection.OneToManyLoader.initialize(OneToManyLoader.java:106)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:484)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1346)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:170)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:47)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:133)
at test.com.wiag.hdb.dao.TestLieferPunktGruppeDAO.testGetLieferPunktVertragByLieferPunktGruppeKey(TestLieferPunktGruppeDAO.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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:



A legacy database used composite business key with a timestamp column. It seems that such a timestamp column as a key column is not supported any more in Hibernate 3.x. Ist there any workaround for this problemm without changing the database schema?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 20, 2005 3:00 am 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
For what is know.

Hibernate takes by default the Hibernate.TIMESTAMP type which do not allow to create a hashCode.
Try setting your column type to Hibernate.DATE.

I use annotatinos so I am not sure if this mapping works, but it should give you a clue.
<property name="your date col">
<type name="DATE" />
</property>

btw: http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-types-custom


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 8:02 am 
Newbie

Joined: Wed Mar 09, 2005 12:54 pm
Posts: 5
What if I need the time information? I just see no reason when the hashcode of a timestamp can't be calculated?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 21, 2005 8:45 am 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
You are right, my suggestion with DATE strips the time part. If you cant change to CALENDAR the only solution I see is to write your own UserType - this isnt too hard.

See
http://cvs.sourceforge.net/viewcvs.py/joda-time/JodaTimeContrib/src/java/org/joda/time/contrib/hibernate/PersistentDateTime.java
how I have done this for joda-time.

The only problem - if you need it - you still might have is the "nanos" part of the timestamp which is stripped too. For what I know this "nanos" part was the base for the decision to remove the hashCode function for Timestamps.


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