-->
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.  [ 2 posts ] 
Author Message
 Post subject: Timestamp in primary key creates error looking up timestamps
PostPosted: Mon Jul 10, 2006 5:50 pm 
Newbie

Joined: Wed Nov 09, 2005 3:55 pm
Posts: 7
Hi,
I'm trying to persist a field of type java.sql.Timestamp to a column of type datetime in sql server 2005. I get an exception :
java.lang.UnsupportedOperationException: cannot perform lookups on timestamps. The field i'm trying to persist is a part of a composite primary key.
I tried running the query directly. it didn't give me any error. So I think the problem is with the primary key class that creates the hash code for the key.
Can I have a timestamp as a part of the key. Does it creates a problem when creating the hash code?

Hibernate version: 3.0

Mapping documents:
<hibernate-mapping package="com.test.pas.common">

<class
name="FluClinic"
table="FluClinic"
dynamic-insert="true"
dynamic-update="true"
>

<composite-id class="com.test.pas.common.keys.FluClinicPK" name="fluClinicPK">


<key-property
name="enteredBy"
type="com.test.pas.common.customtypes.TrimmedString"
column="EnteredBy"
/>

<key-property
column="Enter_TS"
name="enterTimeStamp"
type="timestamp"
/>

<key-property name="HRN"
type="com.test.pas.common.customtypes.TrimmedString">
<column name="HRN" sql-type="character(9)" not-null="true" />
</key-property>

</composite-id>

<property
name="enteredBy"
type="com.test.pas.common.customtypes.TrimmedString"
access="property"
column="EnteredBy"
insert="false"
update="false"
/>


<property
column="Enter_TS"
name="enterTimeStamp"
type="timestamp"
access="property"
insert="false"
update="false"
/>

<property
column="Uploaded_TS"
name="uploadedTimeStamp"
type="timestamp"
access="property"
insert="true"
update="true"
/>

<property
name="HRN"
type="com.test.pas.common.customtypes.TrimmedString"
access="property"
column="HRN"
insert="false"
update="false"
/>


Full stack trace of any exception that occurs:

12:13:55,110 WARN [RequestProcessor] Unhandled Exception thrown: class java.lang.UnsupportedOperationException
12:13:55,110 WARN [RequestProcessor] Unhandled Exception thrown: class java.lang.UnsupportedOperationException
12:13:55,120 ERROR [[action]] Servlet.service() for servlet action threw exception
java.lang.UnsupportedOperationException: cannot perform lookups on timestamps
at org.hibernate.type.TimestampType.getHashCode(TimestampType.java:98)
at org.hibernate.type.AbstractType.getHashCode(AbstractType.java:113)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:199)
at org.hibernate.engine.EntityKey.getHashCode(EntityKey.java:65)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:38)
at org.hibernate.event.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:135)
at org.hibernate.event.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:106)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:180)
at org.hibernate.event.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:31)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:169)
at org.hibernate.event.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:25)
at org.hibernate.event.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:65)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:479)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:474)


Name and version of the database you are using: SQL SERVER 2005

PrimaryKey class

public class FluClinicPK implements Serializable
{

private static final long serialVersionUID = 1L;

// private int hashValue = 0;

private String HRN;
private String enteredBy;
private Timestamp enterTimeStamp;

public FluClinicPK( )
{
// used for hibernate
}


public FluClinicPK( String enteredBy, Timestamp enterTimeStamp, String HRN )
{
this.enteredBy = enteredBy;
this.enterTimeStamp = enterTimeStamp;
this.HRN = HRN;
}

/**
* Implementation of the equals comparison on the basis of equality of the Id components.
*
*/

public boolean equals( Object o )
{
if ( this == o ) return true;
if ( o == null ) return false;
if ( !(o instanceof FluClinicPK) ) return false;
final FluClinicPK fluClinicPK = (FluClinicPK) o;

if ( !enteredBy.equals( fluClinicPK.getEnteredBy( ) ) ) return false;
if ( !enterTimeStamp.equals( fluClinicPK.getEnterTimeStamp( ) ) ) return false;
if ( !HRN.equals( fluClinicPK.getHRN( ) ) ) return false;
return true;
}


public int hashCode( )
{
return (getEnteredBy( ) + getEnterTimeStamp( )+ getHRN( )).hashCode( );

}
// other getters and setters.
}


Please lemme know if I'm doing things correctly.


Thanks,
Anand.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 3:46 pm 
Newbie

Joined: Fri Jun 09, 2006 7:22 am
Posts: 8
I am having a similar problem. I am using Sybase ASE. I have date fields stores as Timestamp. In my Hibernate mapping files I have set the "type" as java.sql.Timestamp. When I try to retrieve objects I get the following exception. The following was thrown when I had requested all rows of a table to bereturned (i.e. there was no where clause). How do I specify the Timestamp format (without changing anyting on the database )


When i retreive objecs that have a timestamp as part of their composit ekey I get an exception. ANd when I try to retreive ALL objects (as explained above) I get the follwing exception.

Code:

by: java.sql.SQLException: JZ009: Error encountered in conversion.  Error message: java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff
   at com.sybase.jdbc2.jdbc.ErrorMessage.raiseError(ErrorMessage.java:485)
   at com.sybase.jdbc2.jdbc.Convert.objectToTimestamp(Convert.java:497)
   at com.sybase.jdbc2.jdbc.Convert.objectToDateObject(Convert.java:565)
   at com.sybase.jdbc2.tds.TdsJdbcInputStream.getDateObject(TdsJdbcInputStream.java:812)
   at com.sybase.jdbc2.jdbc.SybResultSet.getTimestamp(SybResultSet.java:291)
   at com.sybase.jdbc2.jdbc.SybResultSet.getTimestamp(SybResultSet.java:401)
   at org.hibernate.type.TimestampType.get(TimestampType.java:30)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
   at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
   at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
   at org.hibernate.type.ComponentType.hydrate(ComponentType.java:506)
   at org.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:229)
   at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:95)
   at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:1983)
   at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1372)
   at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1300)
   at org.hibernate.loader.Loader.getRow(Loader.java:1197)
   at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:569)
   at org.hibernate.loader.Loader.doQuery(Loader.java:689)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)


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