-->
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.  [ 2 posts ] 
Author Message
 Post subject: Persisting Blob causes commit hang.
PostPosted: Thu Nov 06, 2008 1:49 am 
Newbie

Joined: Tue Sep 09, 2008 3:50 pm
Posts: 4
Location: Minneapolis
Hibernate version: 3

Oracle9i database with Oracle Database 10g Release 2 (10.2.0.4) JDBC Drivers:

The generated SQL (show_sql=true): Will do this asap.

Debug level Hibernate log excerpt: Will investigate how this is done.

I have implemented the solution found here:
http://hansonchar.blogspot.com/2005/06/ ... te-in.html

This involves a class with a one-to-many with a collection of photos. I am experiencing a hang on commit condition when updating the containing class. This occurs even when the code that persists the photos is not being run (i.e. no photos uploaded). The condition does not occur when I comment out ALL the code associated with the collection of photos. I therefore believe this is an annotation related issue since the condition occurs when not persisting photos. I am posting early to find out if anyone has successfully implemented the above solution, and what annotations were used. I am also posting to find out if the above solution is no longer the correct approach.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2008 1:18 pm 
Newbie

Joined: Tue Sep 09, 2008 3:50 pm
Posts: 4
Location: Minneapolis
I have the following additional information. In the SQL log info provided below, the first INSERT operation was successful, but the second INSERT hung on what appears to be an additional UPDATE operation.

Code:
Hibernate: select PHOTO_PK.nextval from dual
Hibernate: insert into MYDB.RENTAL_PHOTO (ACTIVE, CREATE_DTTM, CREATED_BY, DESCRIPTION, IMAGE, IMAGE_BLOB, LAST_UPDATED_BY, LAST_UPDATED_DTTM, RENTAL_NBR, PHOTO_NAME, RENTAL_PHOTO_PK) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update MYDB.RENTAL_PHOTO set ACTIVE=?, CREATE_DTTM=?, CREATED_BY=?, DESCRIPTION=?, IMAGE=?, IMAGE_BLOB=?, LAST_UPDATED_BY=?, LAST_UPDATED_DTTM=?, RENTAL_NBR=?, PHOTO_NAME=? where RENTAL_PHOTO_PK=?



Hibernate: select PHOTO_PK.nextval from dual
Hibernate: insert into MYDB.RENTAL_PHOTO (ACTIVE, CREATE_DTTM, CREATED_BY, DESCRIPTION, IMAGE, IMAGE_BLOB, LAST_UPDATED_BY, LAST_UPDATED_DTTM, RENTAL_NBR, PHOTO_NAME, RENTAL_PHOTO_PK) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update MYDB.RENTAL_PHOTO set ACTIVE=?, CREATE_DTTM=?, CREATED_BY=?, DESCRIPTION=?, IMAGE=?, IMAGE_BLOB=?, LAST_UPDATED_BY=?, LAST_UPDATED_DTTM=?, RENTAL_NBR=?, PHOTO_NAME=? where RENTAL_PHOTO_PK=?
Hibernate: update MYDB.RENTAL_PHOTO set ACTIVE=?, CREATE_DTTM=?, CREATED_BY=?, DESCRIPTION=?, IMAGE=?, IMAGE_BLOB=?, LAST_UPDATED_BY=?, LAST_UPDATED_DTTM=?, RENTAL_NBR=?, PHOTO_NAME=? where RENTAL_PHOTO_PK=?


This snippet of code performs the persist of multiple photos:

Code:
EntityManagerHelper entityManager = EntityManagerHelper.getEntityManager();

   for (File f:fileList) {               
      String fileName = f.getName();
   
      InputStream fileStream = new FileInputStream(f);
      byte[] fileBytes = new byte[fileStream.available()];
      fileStream.read(fileBytes);
            
      RentalPhoto rentalPhoto =
      new RentalPhoto(null, listingNbr, date, userId, date, userId, fileBytes, "Y", fileName, fileName);   
               entityManager.getTransaction().begin();
      entityManager.persist(rentalPhoto);            
      entityManager.getTransaction().commit();
   }


Here is how the EntityManager is created:

Code:
public class EntityManagerHelper {
   
   private static final EntityManagerFactory emf;
   private static final ThreadLocal<EntityManager> threadLocal;
   private static final Logger logger;
   
   static {
      emf = Persistence.createEntityManagerFactory("oMF");       
      threadLocal = new ThreadLocal<EntityManager>();
      logger = Logger.getLogger("oMF");
      logger.setLevel(Level.ALL);
   }
      
   public static EntityManager getEntityManager() {
      EntityManager manager = threadLocal.get();      
      if (manager == null || !manager.isOpen()) {
         manager = emf.createEntityManager();
         threadLocal.set(manager);
      }
      return manager;
   }
   
    public static void closeEntityManager() {
        EntityManager em = threadLocal.get();
        threadLocal.set(null);
        if (em != null) em.close();
    }
   
    public static void beginTransaction() {
       getEntityManager().getTransaction().begin();
    }
   
    public static void commit() {
       getEntityManager().getTransaction().commit();
    } 
   
    public static void rollback() {
       getEntityManager().getTransaction().rollback();
    }
   
    public static Query createQuery(String query) {
      return getEntityManager().createQuery(query);
   }
   
   public static void log(String info, Level level, Throwable ex) {
       logger.log(level, info, ex);
    }
   
}

Any help would be greatly appreciated!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.