How to persist a HashMap with hibernate

前端 未结 2 1193
轮回少年
轮回少年 2020-12-06 07:29

Hello I am very new to the hibernate world and seem to have hit a roadblock. The object I need to store has a hashmap in it.

private Map

        
2条回答
  •  时光说笑
    2020-12-06 08:01

    @org.hibernate.annotations.Type(
            type = "org.hibernate.type.SerializableToBlobType", 
            parameters = { @Parameter( name = "classname", value = "java.util.HashMap" ) }
    )
    public Map getModelData() {
      return modelData;
    }
    

    Or even just this will work in most cases (distributed caching might be a problem):

    @org.hibernate.annotations.Type( type = "org.hibernate.type.SerializableType" )
    public Map getModelData() {
      return modelData;
    }
    

提交回复
热议问题