有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Hibernate映射地图

来自NHibernate,我尝试在Java中执行类似的操作(第一个示例):

http://ayende.com/Blog/archive/2009/06/03/nhibernate-mapping-ndash-ltmapgt.aspx

我有以下代码:

public class Box implements Serializable {
  private Long boxId;
  private Map<String, String> properties;

  public String getProperty(String key) {
    return properties.get(key);
  }
}

在地图中:

<map name="properties" access="field">
  <key column="boxId"/>
  <map-key column="propertyKey" type="string"/>
  <element column="propertyValue" type="clob"/>
</map>

但是,当我试图通过getProperty方法获取属性值时,我得到以下错误:

java.lang.ClassCastException: $Proxy17 cannot be cast to java.lang.String

我是不是忽略了一些显而易见的东西?我真的不明白“$Proxy17”是什么


共 (2) 个答案

  1. # 2 楼答案

    你可以试试<element column="propertyValue" type="string"/>。Hibernate通常足够聪明,可以完成将CLOB转换为字符串的所有工作