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”是什么
# 1 楼答案
要将clob映射到映射中的字符串值,可能需要创建自定义用户类型。。。见本文:http://simoes.org/docs/hibernate-2.1/76.html
# 2 楼答案
你可以试试
<element column="propertyValue" type="string"/>
。Hibernate通常足够聪明,可以完成将CLOB转换为字符串的所有工作