Hi,
May i Know about the concept of BFILE userType Creation in the Hibernate in detail. I tried to create a custom userType going thru the concept from this forum
http://forum.hibernate.org/viewtopic.php?t=947723&postdays=0&postorder=asc&start=0
It is really confusing me to place the file location of a file(say img, pdf, txt etc.,) in the database and retriving the same when i want to display the same img which is being uploaded.
I Tried like this,
Code:
public void fileUpload(Object command) throws Exception {
log.info("FILE UPLOAD");
String dir = "c://FileUpload//GPJ_Repository//";
try {
byte buf[] = new byte[1024 * 4];
Profile profile = (Profile) command;
// Creating Directory
new File(dir).mkdirs();
log.info("Creating Directory"+profile.getUserImage().getContentType());
File file = new File(dir, profile.getUserImage().getOriginalFilename());
log.info("Uploaded File--->"
+ profile.getUserImage().getOriginalFilename());
FileOutputStream output = new FileOutputStream(file);
output.write(profile.getUserImage().getBytes());
try {
InputStream input = profile.getUserImage().getInputStream();
try {
while (true) {
int count = input.read(buf);
if (count == -1) {
log.info("BREAK COUNT--->");
break;
}
// output.write(buf, 0, count);
}
} finally {
input.close();
}
} finally {
output.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
My Profile is having a backing bean of type MultiPartFile of the UserImage.
I created the BFILE Usertype in POJO and my HBM where it maps to oracle's BFILE, when setting the same from my backing bean MultipartFile to BFILE i get ClassCastException.
Would i be able to change my backing bean datatype as BFILE then how will my upload work.
The solution for this problem should be like i should upload the image and download the same. Where im using technologies such as SpringWebflow, Hibernate and Oracle as database connectivity.
I would like to request the peoples who know this concept to brief me in the way i can understand to implement the same.
Help