-->
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.  [ 1 post ] 
Author Message
 Post subject: BFILE in hibernate
PostPosted: Fri Aug 08, 2008 8:45 am 
Beginner
Beginner

Joined: Mon Oct 01, 2007 8:21 am
Posts: 40
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


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

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.