3 Replies Latest reply on Apr 18, 2007 7:15 PM by Shane Bryzak

    <s:fileUpload> problem

    Christopher no Newbie


      I have a problem with <s:fileUpload> control. As a database I'm using DB2 v.8.2. When the receiving field (generated by seamgen) is a Blob type it gets null after a form is submitted. When the receiving field is Byte[] or byte[] type I get mapping exception during JBoss AS startup:

      javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: APPENDIX, expected: varchar(255) for bit data

      When the receiving field is InputStream type I also get mapping exception during JBoss AS startup:

      javax.persistence.PersistenceException: org.hibernate.MappingException: Could not determine type for: java.io.InputStream, for columns: [org.hibernate.mapping.Column(APPENDIX)]

      A form encoding and Seam Multipart servlet filter are configured as in docs and the DB2 (APPENDIX) field is Blob type.
      How can I configure <s:fileUpload> so that it can work properly with DB2?

      Thanks in advance for any help.

      Best regards,

        • 1. Re: <s:fileUpload> problem
          Shane Bryzak Master

          I recommend not binding directly to your entity, because the InputStream binding is by far the most resource efficient and obviously you can't have an InputStream property on your entity bean. Instead I recommend you bind the file data to an InputStream field on a (session bean) component, and then use that to populate your entity.

          • 2. Re: <s:fileUpload> problem
            Christopher no Newbie


            thanks for the recommendation but suppose that we have the following classes:

            public class Document implements Serializable{
             InputStream file;
             public InputStream getFile() {
             return file;
             public void setFile(InputStream file) {
             this.file = file;
            public class DocumentHome extends EntityHome<Document>{
             protected Document createInstance(){
             Document document = new Document();
             return document;
            @Table(name = "PROFILE_APPENDIX", schema = "DB2USER")
            public class ProfileAppendix implements java.io.Serializable {
             private long id;
             private Profile profile;
             private String name;
             private String description;
             private Blob appendix;
            public class ProfileAppendixHome1 extends EntityHome<ProfileAppendix1> {
             @In(create = true)
             ProfileHome profileHome;
             EntityManager entityManager;
             DocumentHome documentHome;
             public void saveProfileAppendix(){}

            When the form is submitted "file" variable from Document class is populated but I don't know how
            to populate Blob appendix variable in saveProfileAppendix() function using
            documentHome.instance.getFile(). How to cast InputStream to Blob?
            Any help appreciated.

            Best regards,

            • 3. Re: <s:fileUpload> problem
              Shane Bryzak Master

              I believe that you'd use Blob.setBinaryStream() to get the blob's OutputStream, then write the data from the file's InputStream to that. Maybe someone more knowledgeable about using blob fields can comment on this?