-->
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: Problem with composite key containing date
PostPosted: Wed Feb 23, 2005 11:40 am 
Newbie

Joined: Wed Feb 23, 2005 11:29 am
Posts: 9
I am getting error with composite key with date column (e.g. PK is business date and order num).

Hibernate version: 3.0 beta 4

Mapping documents:
<class name="xyz.Bar" table="xxx_table">
<composite-id name="id">
<key-property name="busDate" column="BusDate"/>
<key-property name="orderNum" column="OrderNum"/>
</composite-id>
<property name="note" column="Note"/>
</class>

BarId.java:
public class BarId implements Serializable
{
private Date busDate;
private int orderNum;

public Date getBusDate() { return busDate; }
public void setBusDate(Date busDate) { this.busDate = busDate; }

public int getOrderNum() { return orderNum; }
public void setOrderNum(int orderNum) { this.orderNum = orderNum; }

public boolean equals(Object other)
{
if (this == other) {
return true;
}

if (!(other instanceof BarId)) {
return false;
}

BarId k = (BarId)other;

return busDate.equals(k.getBusDate()) && orderNum == k.getOrderNum();
}

public int hashCode() { return busDate.hashCode() ^ orderNum; }
}

Bar.java:
public class Bar
{
private BarId id;

private String note;

public BarId getId() { return id; }
public void setId(BarId id) { this.id = id; }

public String getNote() { return note; }
public void setNote(String note) { this.note = note; }
}

// The following code generates exception (session.load...)
BarId id = new BarId();
id.setBusDate(java.sql.Date.valueOf("2005-01-01"));
id.setOrderNum(1);

Bar bar = (Bar)session.load(Bar.class, id);

Full stack trace of any exception that occurs:[/b]

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.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:67)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:599)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:594)
at mytest.entity.BarTest.testBar(BarTest.java:29)
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 junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
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:
Sybase 12 or MS SQL server 2000


Top
 Profile  
 
 Post subject: Found the problem(s) myself....
PostPosted: Thu Feb 24, 2005 9:00 am 
Newbie

Joined: Fri Jan 14, 2005 4:58 am
Posts: 10
I migrated my mapping files from version 2.1 and forgot to change the references to the DTD to 3.0.... I had also forgot the mandatory key attribute....

Works fine now!


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.