-->
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: java.io.InvalidClassException:Date & serialVersionUID
PostPosted: Sat Feb 19, 2005 7:31 am 
Beginner
Beginner

Joined: Tue Feb 08, 2005 1:29 pm
Posts: 20
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


Top
 Profile  
 
 Post subject: I have same problem....
PostPosted: Wed Jun 15, 2005 10:58 am 
Regular
Regular

Joined: Thu Sep 09, 2004 6:46 pm
Posts: 96
I have same problem.... Any ideas?


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.