How to insert blob in ejb


EJB programming & troubleshooting: How to insert blob in ejb

  1. How to insert blob in ejb (1 messages)

    In pure JDBC such as servlet, I can insert BLOB to Oracle database. However, in ejb such as SLSB or entity bean, I don't know how to insert blob. One thread suggests using byte array. However in oracle thin driver, setBytes() just supports up to 4000 bytes. If I want to use a stream for blob filed, how do I do it?

    In jdbc such as servlet, I am using following code to insert blob to database.

    In Oracle database, if I want to insert or update LOB, I have to use
    ResultSet resultSet = Statement.executeQuery("select ... for update");
    Blob blob = resultSet.getBlob();
    OutputStream inputStream = blob.getOutputStream();

    How do I implement the above code in ejb because I can not run any setCommit() or commit() in ejb container? If I use UserTransaction.begin() and UserTransaction.commit() to replace setAutoCommit(false) and commit(), it doesn't work.

  2. How to insert blob in ejb[ Go to top ]

    I think you can use CMP Entity Bean. You need to map the BLOB/CLOB type in the container specific descriptor file, the container will take care of the persistance.

    For Weblogic:



    For Oc4j:
    <entity-deployment name="EmployeePicture" data-source="jdbc/OracleDS" table="EMPPIC">
            <cmp-field-mapping name="empno" persistence-name="EMPNO" persistence-type="NUMBER(8)"/>
          <cmp-field-mapping name="empno" persistence-name="EMPNO" persistence-type="NUMBER(8)"/>
          <cmp-field-mapping name="picture" persistence-name="PICTURE" persistence-type="BLOB"/>