简体   繁体   中英

Use hibernate when saving objects to the database

In my java application I have some serialized entity classes with inheritance. When saving instances of these classes i am converting them to a byte array and saving to a longblob column in my database table. Is there any advantage using hibernate to implement this program. Because as far I understand hibernate is used to map entities with database tables in a proper way. But here I don't have a relational model to map attributes of entities. I am saving them as objects. Am I missing something. Please clarify me. Thanks in advance.

If you don't have a relational data model to save those objects and you can't change your schema, then you can use your current approach.

If you use PostgreSQL you might be interested in JSON storage as well. That way you can store your hierarchies using JSON objects and you can even run native SQL queries against them (although not inheritance-aware, but you can cope with that if you use some _class column to differ between object types).

The cleanest approach is to have the relation model in sync with your business domain model. That way you can benefit from:

  • optimistic locking ( preventing lost updates phenomena )
  • caching (2nd level cache and query cache)
  • query-able hierarchies
  • an external DBA hierarchies could run an update on your hierarchies using mere SQL
  • auditing

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM