Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

using longblob in hibernate

807580Sep 14 2010 — edited Sep 14 2010
I'm new to the hibernate world and i am using it to map a table that stores files of all types. i am however recieving a very strange error :

javax.servlet.ServletException: java.lang.ClassCastException: [B cannot be cast to java.sql.Blob

I have mapped my MySql LONGBLOB column has: `<property name="fileData" type="blob" .../>` and `<property name="fileData" type="longblog" .../>` but both dont work.

I'm currently using spring mvc version 3.x the latest version and tomcant 7 if that helps.

edit: here is how my POJO looks like for fileObject:

[CODE]package com.kc.models;

public class FileObject {

private String fileName;
private String type;
private double size;
private byte[] file;
private int id;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getSize() {
return size;
}
public void setSize(double size) {
this.size = size;
}
public byte[] getFile() {
return file;
}
public void setFile(byte[] file) {
this.file = file;
}



}


And here is how my hbm.xml file looks like:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.kc.models.FileObject" >

	<class name="com.kc.models.FileObject" table="FILES">
		<id name="id" column="ID">
			<generator class="native" />
		</id>
		<property name="fileName" type="string" column="FILENAME" />
		<property name="type" type="string" column="TYPE" />
		<property name="size" type="double" column="SIZE" />
		<property name="file" type="blob" column="FILE" />
	</class>

</hibernate-mapping>
O and here is a print screen of mySql:
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 12 2010
Added on Sep 14 2010
1 comment
809 views