I don't know what's the best way to save a HashMap in the database (the HashMap can be very big) so I my first idea is to save the HashMap as a blob (in a column), an other idea was to save every value in the HashMap corresponding to the key but this would make it to large I thought.
My example class:
public class MyObject {
private int id;
private HashMap<Integer, CustomHash> hashes;
// getters and setters
}
I also heard of serializing the class and save it in the database. Any suggestions?
Also no use of ORM only plain JDBC
EDIT: how to save hashmap into clob?
CREATE TABLE IF NOT EXISTS myobjects (
id int GENERATED BY DEFAULT AS IDENTITY(START WITH 1) PRIMARY KEY,
hashes clob NOT NULL
);
My statement:
PreparedStatement ps = null;
try {
ps = this.connection.prepareStatement("INSERT INTO myobjects (hashes) VALUES (?)");
ps.setClob(1, (Clob) myObject.getHashes());
ps.executeUpdate();
} catch(SQLException sqlEx) {
sqlEx.printStackTrace();
} finally {
DAOUtility.close(this.connection, ps);
}
The error: HashMap cannot be cast to Clob