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
|
|