tags:

views:

46

answers:

2

Coming from NHibernate, I've tried to do something like this in Java (first example):

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

I have the following code:

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

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

And in the mapping:

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

But when I try to get a property value through the getProperty method, I get the following error:

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

Am I overlooking something obvious here? I don't really get what "$Proxy17" is.

+1  A: 

To map the clob to a string value in your map, you might need to create a custom user type... see this article: http://simoes.org/docs/hibernate-2.1/76.html

limc
+1  A: 

You might try <element column="propertyValue" type="string"/> instead. Hibernate is usually smart enough to do all the work of converting clobs to strings.

Jherico