Discussions

EJB programming & troubleshooting: Does ejb Entity support blob insert

  1. Does ejb Entity support blob insert (6 messages)

    Can anybody post example of how to insert blob file using CMP or BMP bean.
  2. No till Ejb 1.1 inserting of a blob is not supported.
    You have to used it in the traditional jdbc way by inserting a byte array and then updating that with the blob reading byte by byte.

    But you can retreive the blob with any finder method of the entity beans.

    Hope this helps..

    regards
    Nagendra...
  3. Insert BLOB[ Go to top ]

    Sure you can use BLOB in EB 1.1 ;-)
    Just use a normal serializeable Java object. I'm using it in OpenUSS to handle attachment for my discussion forum EJB 1.1.
    You can download the complete code (OpenUSS == Open Source) from http://openuss.sourceforge.net

    Hope this helps!
    Lofi Dewanto

    Example from OpenUSS (http://openuss.sourceforge.net):

    ...

    public class DiscussionFileBaseBean extends EntityAdapter
        implements DiscussionFileBase {
     
        public String id;

        // Object state
        public DiscussionFileObject file;

        public DiscussionFileBasePK ejbCreate(String id, DiscussionFileObject file)
                                       throws CreateException {
            this.id = id;
            this.file = file;
            return null;
        }

        /**
         * Gets the file of the discussion.
         *
         * @return the file of the discussion.
         * @exception EJBException.
         */
        public DiscussionFileObject getFile() {
            return file;
        }

        /**
         * Gets the file of the discussion.
         *
         * @param the file to be changed.
         * @exception EJBException.
         */
        public void setFile(DiscussionFileObject file) {
            // Check first, if the param is null, don't update this!
            // Let the old value survive!
            if (!(file == null)) {
                // Check the length of the file
                if (file.getData().length != 0) {
                    // File is not empty
                    this.file = file;


                    // EJB container specific
                    setModified(true);
                }
            }
        }

    ...
  4. Can anybody post example of how to insert blob file using CMP or BMP bean.


    Using the oracle.xml file in j2ee\home\config\database-schemas, I just mapped
    a byte array to a blob in the db table, and used CMP. So in the Entity bean I
    just work with a byte array, and the blob storage is transparent.

    In oracle.xml
    add this line
    <type-mapping type="byte []" name="blob" />

    In the Entity bean declare
    public abstract byte [] getData_file();
    public abstract void setData_file(byte [] newData_file);

    In the create
    public String ejbCreate(String newFwc,String newPart_no,String newMedia,
                              String newProd,String newTcode,String newSource,
                              String newCdate,String newCtime,String newLast_acc,
                              String newProg,String newRuntm,String newNdown,
                              byte [] newData_file,String newViewer,
                              String newDb)throws CreateException
      {
       .......
       .......
       setData_file(newData_file);
       }

        So I don't have to work with JDBC blob or BLOB handling, or database
    stored procedures. I just call get or set. The container implements those
    functions for me.
  5. Hi Everyone

    Andy Stefancik your example did work and I was able to successfully upload a blob file of 95 kb. Once again thanx to everyone who replied....your help is deeply appericated :)

    Example tried on system configuration ---> "JBoss 3.2.XXX and Mysql 4.0.3"

    Have a nice week
    Tim
  6. Hi,

    Thanks for your post and it works well. I guess there is a size limitation of 4k. I dont know if it is on the oracle database server or the appserver. We are using oracle application server(9IAS). I used a byte array to save the file into the database. It works like a charm when I upload the file less than 4k. Once you cross the limit of 4k its throwing erros.

    Any Idea of how I can fix it?

    I am reletively new to application servers.

    Thanks
    Binny
  7. What version of OC4J are you using ? This works out of the box in 9.0.4

    For 9.0.3, there is patch available

    -Debu