• Post Reply Bookmark Topic Watch Topic
  • New Topic

Spring-Hibernate-Blob problem  RSS feed

 
Maneeesh Saxena
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Great Ranchers,

I am facing problem while saving Blob object (which represents a file being uploaded). When I run this code I don't get my object saved. Please suggest where I am missing something to get code working properly.



Employee.java

public class Employee implements Serializable {
long id;
private String name;
private String department;
private String projectTitle;
private String projectDescription;
private Blob content;
...................................


Employee.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.test.beans.Employee" table="Employee">
<id name="id" type="long" column="ID">
<generator class="assigned" />
</id>

<property name="content" type="blob">
<column name="CONTENT" />
</property>
...................................


MyDaoImpl.java

Blob blob = null;
InputStream in = file.getInputStream(); //File being uploaded
blob = Hibernate.createBlob(in);
employee.setContent(blob);
hibernateTemplate.saveOrUpdate(employee);
.......................................................


Thanks & Best Regards
Maneesh Saxena
 
Maneeesh Saxena
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Now I am able to upload file in database now the problem is I've to download the file. I've googled a lot but could not find any web app for doing the same please help me in this ...


Best Regards
Maneesh Saxena
 
Josean Delgado
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I believe this article I wrote recently, might be relevant to your question...

In the article I used Spring Roo for its implementation, however I refer to another implementaion using regular Spring too.

Here is the link: http://viralpatel.net/blogs/2011/02/spring-roo-save-read-blob-object-spring-roo-tutorial.html.

I hope it helps you

jD
 
Radovan Vukovic
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!