-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Hibernate 3.6 Blob Problem
PostPosted: Fri Jan 14, 2011 12:17 pm 
Newbie

Joined: Fri Jan 14, 2011 11:48 am
Posts: 2
We recently started using Hibernate 3.6 in a new application we're coding. I need to convert an object to a Blob for storage. I can successfully convert the object to a byte array and then create a blob from it, but I can't get it to store into the database. I've tried using the LobHelper class and the deprecated Hibernate.createBlob() methods, but with the same result. As soon as I call save on the object to write it to the database, I get this nasty exception:

SEVERE: Servlet.service() for servlet pgx_jmillv2_millweb_scheduler threw exception
java.lang.ClassCastException: $Proxy8 cannot be cast to oracle.sql.BLOB
at oracle.jdbc.driver.OraclePreparedStatement.setBlob(OraclePreparedStatement.java:6162)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setBlob(OraclePreparedStatementWrapper.java:126)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setBlob(NewProxyPreparedStatement.java:495)
at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$1.doBind(BlobTypeDescriptor.java:65)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:89)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:282)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:85)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2166)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2412)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2856)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1709)
at sun.reflect.GeneratedMethodAccessor160.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344)
at $Proxy4.list(Unknown Source)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
at com.pgba.hibernate.DirectHibernateConnection.get(Unknown Source)
at com.pgba.millweb.controller.scheduler.admin.AdminJobController.initAdminJob(AdminJobController.java:97)
at com.pgba.millweb.controller.scheduler.admin.AdminJobController.addAdminJob(AdminJobController.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.pgba.common.controller.AbstractMultiActionFormController.processFormSubmission(AbstractMultiActionFormController.java:182)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:268)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.pgba.hibernate.HibernateFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.pgba.util.servlet.SessionFilter.doFilter(Unknown Source)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

We're using the latest Hibernate and c3p0 versions going to an Oracle 11i database.

Any ideas what might be causing this?

Thanks,
akempo


Top
 Profile  
 
 Post subject: Re: Hibernate 3.6 Blob Problem
PostPosted: Fri Jan 14, 2011 3:04 pm 
Newbie

Joined: Fri Jan 14, 2011 11:48 am
Posts: 2
Found it - turned out to be a mapping issue in the hbm file, of all things. Just had to change the way Hibernate reverse engineered the blob a little bit is all and that took care of it.


Top
 Profile  
 
 Post subject: Re: Hibernate 3.6 Blob Problem
PostPosted: Thu Feb 03, 2011 10:06 am 
Newbie

Joined: Wed Feb 02, 2011 2:51 pm
Posts: 1
Can you post the solution, we are having a similar issue.


Top
 Profile  
 
 Post subject: Re: Hibernate 3.6 Blob Problem
PostPosted: Wed May 04, 2011 1:21 pm 
Newbie

Joined: Wed May 04, 2011 1:12 pm
Posts: 4
We are having a similar problem after moving from Hibernate 3.3 to 3.6.

The mapping for the blob property looks like this:

<property
name="attachmentBlob"
type="java.sql.Blob"
column="ATTACHMENT_BLOB"
not-null="true"
length="4000"
/>

Here is example code that creates and saves the Blob:

org.hibernate.Session session = // get a hibernate session
File file = new File("/tmp/foo.png");
Blob attachmentBlob = session.getLobHelper().createBlob(new FileInputStream(file), file.length());
emailAttachment.setAttachmentBlob(attachmentBlob);
session.save(emailAttachment);
session.flush();

This results in:

java.lang.ClassCastException: $Proxy6 cannot be cast to oracle.sql.BLOB
at oracle.jdbc.driver.OraclePreparedStatement.setBlob(OraclePreparedStatement.java:6890)
at org.hibernate.type.descriptor.sql.BlobTypeDescriptor$1.doBind(BlobTypeDescriptor.java:65)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:89)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:282)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:277)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:85)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2166)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2412)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2856)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)

The attachmentBlob is an instance of class org.hibernate.engine.jdbc.BlobProxy, evidently the Hibernate engine tries to cast this to a native Blob type and it fails. We are using Oracle 10.

This used to work with Hibernate 3.3 and seems to be about as simple as can be. What is the correct way to do this?

A related question, this link:

http://www.hibernate.org/56.html

is referenced in other forums and is supposed to have information about blobs. But the link no longer works, where can this information now be found?

Thanks in advance for any help.


Top
 Profile  
 
 Post subject: Re: Hibernate 3.6 Blob Problem
PostPosted: Wed May 04, 2011 5:56 pm 
Newbie

Joined: Wed May 04, 2011 1:12 pm
Posts: 4
I think I figured this out, and would like to share the solution with the forum.

First, as a workaround, I found that I could change the property type in the hibernate mapping from "java.sql.Blob" or "blob" to "binary", and change the Java type of the ivar from "Blob" to "byte[]". This allows saving of blob data, though in our case this required us to change all of the callers to our Hibernate class which was disruptive.

I also found this bug:

http://opensource.atlassian.com/project ... e/HHH-5830

which is in 3.6.0 and fixed in 3.6.1. I was running 3.6.0, so I may have encountered this bug. I had already coded the workaround I mentioned above by the time I found this bug, and I have not gone back to see if upgrading our version of Hibernate fixed that problem. This gives others 2 avenues to pursue to find an answer.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.