0 Replies Latest reply on May 5, 2008 12:06 PM by Anandu Suri

    Exception inserting BLOBs

    Anandu Suri Newbie

      Hello all,


          I don't even know if this is the right place to post this. I have been trying to insert images in a oid column of postgreSQL table. I could somehow manage to use s:fileUpload to read the content into an input stream. But whenever I try em.persist(), an exception occurs saying that Blob cannot be manipulated from creating a session.


      I googled this exception, but nothing turned up. The Hibernate site had a solution but it was for session object where they seem to open a transaction. Hibernate doc seems to be confusing in that they say the @PersistenceContext should do all transaction work when using JTA. But still the exception occurs.


      Here's my Entity


      @Entity
      public class TestNode implements java.io.Serializable {
          private static final long serialVersionUID = 1L;
          @Id
          @GeneratedValue(strategy = GenerationType.IDENTITY)
          long id;
          @Column
          String fileName;
          @Lob
          Blob image;
          ///Getters and setters
      



      And here is my seam code



      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
          public String upload() {
              TestNode tmp \= new TestNode();
              try {
                  tmp.setFileName(fileName);
                  tmp.setImage(Hibernate.createBlob(localStream));
                  entityManager.refresh(tmp);
                  entityManager.persist(tmp);
                  FacesMessages.instance().add("Uploaded.");
              }
              catch (Exception e) {
                  e.printStackTrace();
                  FacesMessages.instance().add("Failed.");
              }
              return "/test.seam";
          }
      




      This class is annotated as @Stateful and @Name("TestUpload")


      Am I doing something wrong? How to open a new transaction as it is opened in Hibernate?