映射映射< String,String>使用Hibernate [英] Mapping Map<String,String> using Hibernate

查看:121
本文介绍了映射映射< String,String>使用Hibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来,我看到的每个地方都有过时的版本,这些版本已经不再适用。
我的问题似乎很简单。我有一个Java类的类,它映射到一个德比数据库。我正在使用注释,并成功地在我的数据库中创建了所有其他表,但是在这个特定示例中,我只需要一个不使用任何其他类的Map,只有两个简单的字符串值。我遇到了所有类型的错误,尝试我在网上找到的一切。



有没有人知道这样做的简单方法,而不使用已弃用的注释?



预先感谢! html / entity.html#entity-mapping-associationrel =nofollow noreferrer> Hibernate Annotations文档的第2.2.5.3.4节介绍了必要的注释。您需要执行以下操作:

  @Entity 
public class MyEntity {
...
$ b $ @ElementCollection //这是一个基元集合
@MapKeyColumn(name =key)//映射key的列名
@Column(name =value )//地图值的列名
public Map< String,String> getMyMap(){

...
}


It seems that everywhere I look, there are outdated versions of this which no longer work. My problem seems really simple. I have a class in Java, which maps to a derby database. I'm using annotations, and have successfully managed to create all the other tables in my DB, yet with this specific example, where I just need a Map, which does not use any other class, just two simple string values. I have come across all types of errors trying everything I've found online.

Does anybody know of a simple way of doing this, without using deprecated annotations?

Thanks in advance!

解决方案

Chapter 2.2.5.3.4 of Hibernate Annotations documentation describes the necessary annotations. You need to do something like:

@Entity
public class MyEntity {
    ...

    @ElementCollection // this is a collection of primitives
    @MapKeyColumn(name="key") // column name for map "key"
    @Column(name="value") // column name for map "value"
    public Map<String,String> getMyMap() {

    ...
}

这篇关于映射映射&lt; String,String&gt;使用Hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆