Java – stores serializable objects in the database
I'm writing an application that needs to write objects to the database
For simplicity, I want to serialize objects
But the objectouputstream required for the same purpose has only one constructor, which takes any subclass of OutputStream as a parameter
What parameters should be passed?
Solution
You can pass bytearrayoutputstream, and then the generated stream Tobytearray () is stored in the database as a blob
Make sure to specify serialVersionUID for the class, otherwise you will encounter difficulties in adding / removing fields
If you need more human readable data, consider the XML version of object serialization - xmlencoder. XML
Finally, you may want to transform the object model into a relational model through the ORM framework JPA (hibernate / eclipse link / openjpa) provides object relational mapping so that you can use objects, but their fields and relationships will remain in the RDBMS