I am sure about of the code, you will understand what I am trying to achieve. At the end I have an exception:
java.io.InvalidClassException: java.util.Date; local class incompatible: stream classdesc serialVersionUID = 7523895402267505689, local class serialVersionUID = 7523967970034938905
The table:
CREATE TABLE `test` (
`PRODUCTID` char(12) NOT NULL default '',
`LSTTRDTIM` datetime default NULL,
`TIMESTAMP` bigint(20) unsigned NOT NULL default '0',
PRIMARY KEY (`PRODUCTID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
The mapping:
<hibernate-mapping package="test" >
<class name="Test" table="TEST" >
<id name="productId" type="java.lang.String" unsaved-value="null" column="PRODUCTID" >
<generator class="assigned"/>
</id>
<property name="lastTradedTime" type="java.util.Date" column="LSTTRDTIM" />
<property name="timestampDB" type="long" column="TIMESTAMP" />
</class>
</hibernate-mapping>
AND
<hibernate-configuration>
<session-factory>
<!-- properties -->
<property name="connection.username">root</property>
<property name="connection.password">puifefof</property>
<property name="connection.url">jdbc:mysql://localhost/mysql</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>
<property name="cglib.use_reflection_optimizer">false</property>
<!-- mapping files -->
<mapping resource="test/Test.hbm.xml" />
</session-factory>
</hibernate-configuration>
My Test class is:
public class Test extends Object implements Serializable {
static final long serialVersionUID = 4557539103552154029L;
private String productId;
private Date lastTradedTime;
private Timestamp timestamp;
public Test() {
}
public Date getLastTradedTime() {
return lastTradedTime;
}
public String getProductId() {
return productId;
}
public Timestamp getTimestamp() {
return timestamp;
}
public void setLastTradedTime(Date t) {
lastTradedTime = t;
}
public void setProductId(String s) {
productId = s;
}
public void setTimestamp(Timestamp t) {
timestamp = t;
}
/*
* The database is storing the timestamp under the form of big integer.
*/
protected long getTimestampDB() {
return timestamp.getTime();
}
protected void setTimestampDB(long t) {
timestamp = new Timestamp(t);
}
}
public class DvJTest {
public static void main(String[] args) {
try {
ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(outputBuffer);
String blob;
Test marketInfo = new Test();
marketInfo.setProductId("WHATEVER");
HibernateUtil.currentSession().load(marketInfo, "WHATEVER");
outputStream.writeObject(marketInfo);
blob = outputBuffer.toString();
outputStream.close();
ByteArrayInputStream inputBuffer = new ByteArrayInputStream(blob.getBytes());
ObjectInputStream inputStream = new ObjectInputStream(inputBuffer);
marketInfo = (Test) inputStream.readObject();
System.out.print("Ok!!!");
} catch (IOException ex) {
System.out.print("Error!!!");
} catch (ClassNotFoundException ex) {
System.out.print("Error!!!");
} catch (HibernateException ex) {
System.out.print("Error!!!");
}
}
}
What is wierd is if I remove in the mapping the line related to the timestamp, this is working.
Can someone help please? I have been on that problem for 2 nights now!!!
Thanks.
ingenu
|