Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to cast a Hashmap type to a Clob?

 
chaohua wang
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, folks,

I have a hibernate POJO object, which has a method

public void setResults(Clob results) {
this.results = results;
}


but i have variable pro, which is Map type and has some values.
I need to pass this Haspmap value to this mehtod,
like this,
dataobject.setResults((Clob)pro);

it can complie. but when i run it,

I got an exception,
17:24:12,332 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:166)
17:24:12,332 ERROR [STDERR] Caused by: javax.transaction.TransactionRolledbackException: java.util.HashMap cannot be cast to java.sql.Clob; nested exception is:
java.lang.ClassCastException: java.util.HashMap cannot be cast to java.sql.Clob

How can i fix this issue? there is any way to cast Hashmap to a Clob.
Please help, Thank you!

Chwang
 
Anshul Malpani
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot type cast a map directly to Clob. You do (Clob)map.get("clob")
Try this . and tell
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, there's no is-a relationship between a HashMap and a Clob. That's a stop sign right there.

You'll need to get the Clob, un-Clob it yourself, and massage it into the appropriate type.

If it was a HashTable originally, how did you Clob it? Could you just do the reverse?

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic