Hi,

I have searched the documentation and the group, and have not found an
answer to this question. I am hoping I am just making a simple mistake
in my approach, but I have been unable to figure out where my error
lies.

I have a simple table defined via: "Create Table TEST( ID VARCHAR(16),
Record OTHER);"

I want to store my record class into the table, so I have code similar
to:

public void storeMyRecord( Map<String, Object> map) throws Exception
{
  PreparedStatement ps = null;
  Object[] inputValues = new Object[2];

  inputValues[0] = map.get("ID");
  inputValues[1] = map.get("Record");

  String insertSQL = "Insert into TEST (Id, Record) values(?,?)";

  ps = conn.prepareStatement( insertSQL );

  ps.setObject(1, inputValues[0]);
  ps.setObject(2, inputValues[1]);

  ps.executeUpdate();

}

Then, to retreive the records I have:

public MyRecord retreiveRecord( Map<String, Object> map ) throws
Exception
{
  ResultSet rs = null;
  PreparedStatement ps = null;

  String querySQL = "Select Record from TEST where Id=?";

  ps = conn.prepareStatement(querySQL);

  ps.setObject(1, map.get("ID");

  rs = ps.executeQuery();
  rs.next();
  Object o = rs.getObject(1);

  MyRecord rec = (MyRecord)o;

  return rec;
}

Now, when I call the code, the store method works fine, but when I
call the retrieve method, I get an exception on the line: Object o =
rs.getObject(1);

that says:
org.h2.jdbc.JdbcSQLException: Deserialization failed, cause:
"java.lang.ClassNotFoundException:
com.test.types.MyRecord" [90027-127]
        at org.h2.message.Message.getSQLException(Message.java:110)
        at org.h2.util.ObjectUtils.deserialize(ObjectUtils.java:66)
        at
org.h2.jdbc.JdbcConnection.convertToDefaultObject(JdbcConnection.java:
1674)
        at org.h2.jdbc.JdbcResultSet.getObject(JdbcResultSet.java:461)

I understand that the exception is occurring because the org.h2 code
has no idea what a 'MyRecord' class is, down in the
org.ht.util.ObjectUtils.deserialize() method, but again, not sure why
its trying to get it as the 'MyRecord' class rather than an Object
class.

Am I missing something basic here, or is there some trick I just
haven't learned yet? :)

Thanks for any suggestions!
-Al


-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to