Is it possible to map a Map<String, Object> with Hibernate?
All is in the qu开发者_如何学编程estion. How to map a Map with Hibernate using annotations ? And what's the associated database structure ?
You are probably looking for a generic key-value database structure where values can have multiple types. This is typically resolved by having some sort of abstract Value
class with key attribute and several subclasses, each for every desired type:
Now you use:
Map<String, Value>
Of course this approach has many disadvantages, correctly choosing inheritance strategy being one of them (it depends on how many different types you want to store). But at least it is perfectly type-safe.
I don't have any experience with NHibernate, but with Hibernate (see: How do you map a "Map" in hibernate using annotations?) you can map Map
directly.
精彩评论