I am trying to insert all the data at once using the following:
userModel.setServiceData(gson.toJson(sortedResponse).getBytes());
This is giving Out of Memory for the huge data.
So I am trying to add data in chunks to the postgres database using something like:
byte[] chunkedMessage = {};
for (Iterator<Message> iterator = sortedResponse.iterator(); iterator.hasNext();) {
Message message = (Message) iterator.next();
chunkedMessage = gson.toJson(message).getBytes();
userModel.setServiceData(chunkedMessage);
}
Obviously, this will end up storing the last chunk but not all chunks collectively.
I am using hibernate so thinking if there is any easy way with hibernate query or may be as easy as something in the above code.