来自 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”是什么。
最佳答案
您可以尝试<element column="propertyValue" type="string"/>
反而。 Hibernate 通常足够聪明,可以完成将 clob 转换为字符串的所有工作。
关于java - Hibernate 映射 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3199021/