开发者

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:

UML

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜