Image file in DB entry does not

I try to have the user select an image file, and then insert into a db however I get this db error "entity line with null key is not found in NblNhIncsubmission."

If you see my picture below you can see my code is correctly downloaded the file and update the "Attachment" field, but it throws an error inserting the entire form in the db

Here's the PB I need to insert in (circled is the column I'm inserting the NblNhIncsubmission DB)

Here is my page jspx code:

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1" binding="#{backingBeanScope.backing_Test.d1}">
      <af:messages binding="#{backingBeanScope.backing_Test.m1}" id="m1"/>
      <af:form id="f1" binding="#{backingBeanScope.backing_Test.f1}"
               usesUpload="true">
        <af:pageTemplate viewId="/oracle/templates/threeColumnTemplate.jspx"
                         id="pt1">
          <f:facet name="center">
            <af:panelFormLayout binding="#{backingBeanScope.backing_Test.pfl1}"
                                id="pfl1">
              <af:spacer width="10" height="10"
                         binding="#{backingBeanScope.backing_Test.s2}" id="s2"/>
              <af:inputDate value="#{bindings.When.inputValue}" label="WHEN"
                            shortDesc="#{bindings.When.hints.tooltip}"                        
                            id="it6" required="true" showRequired="true"/>
              <af:spacer width="10" height="10"
                         binding="#{backingBeanScope.backing_Test.s1}" id="s1"/>
              <af:selectOneChoice value="#{bindings.Location.inputValue}"
                                  label="LOCATION"
                                  shortDesc="What is your location?"
                                  binding="#{backingBeanScope.backing_Test.soc1}"
                                  id="soc1" showRequired="true" required="true">
                <f:selectItems value="#{bindings.Location.items}"
                               binding="#{backingBeanScope.backing_Test.si1}"
                               id="si1"/>
              </af:selectOneChoice>
              <af:spacer width="10" height="10"
                         binding="#{backingBeanScope.backing_Test.s3}" id="s3"/>
              <af:selectOneChoice value="#{bindings.Category.inputValue}"
                                  label="OBSERVATION TYPE"
                                  shortDesc="Describe the cause of your observation."
                                  binding="#{backingBeanScope.backing_Test.soc2}"
                                  id="soc2" required="true" showRequired="true">
                <f:selectItems value="#{bindings.Category.items}"
                               binding="#{backingBeanScope.backing_Test.si2}"
                               id="si2"/>
              </af:selectOneChoice>
              <af:spacer width="10" height="10"
                         binding="#{backingBeanScope.backing_Test.s4}" id="s4"/>
              <af:inputText value="#{bindings.Details.inputValue}"
                            label="YOUR OBSERVATION"
                            columns="#{bindings.Details.hints.displayWidth}"
                            maximumLength="#{bindings.Details.hints.precision}"
                            shortDesc="#{bindings.Details.hints.tooltip}"
                            binding="#{backingBeanScope.backing_Test.it3}"
                            id="it3" required="true">
                <f:validator binding="#{bindings.Details.validator}"/>
              </af:inputText>
              <af:spacer width="10" height="10"
                         binding="#{backingBeanScope.backing_Test.s5}" id="s5"/>
              <af:inputText value="#{bindings.Action.inputValue}"
                            label="ACTION TAKEN"
                            columns="#{bindings.Action.hints.displayWidth}"
                            maximumLength="#{bindings.Action.hints.precision}"
                            shortDesc="#{bindings.Action.hints.tooltip}"
                            binding="#{backingBeanScope.backing_Test.it4}"
                            id="it4" showRequired="true" required="true">
                <f:validator binding="#{bindings.Action.validator}"/>
              </af:inputText>
              <af:spacer width="10" height="10"
                         binding="#{backingBeanScope.backing_Test.s6}" id="s6"/>
              <af:inputText value="#{bindings.Attachment.inputValue}"
                            label="#{bindings.Attachment.hints.label}"
                            required="#{bindings.Attachment.hints.mandatory}"
                            columns="#{bindings.Attachment.hints.displayWidth}"
                            maximumLength="#{bindings.Attachment.hints.precision}"
                            shortDesc="#{bindings.Attachment.hints.tooltip}"
                            binding="#{backingBeanScope.backing_Test.it2}"
                            id="it2" rendered="true">
                <f:validator binding="#{bindings.Attachment.validator}"/>
              </af:inputText>            
              <af:spacer width="10" height="10"
                         binding="#{backingBeanScope.backing_Test.s8}" id="s8"/>
              <af:inputFile label="Upload File"
                            binding="#{backingBeanScope.backing_Test.if1}"
                            id="if1"
                            value="#{backingBeanScope.backing_Test.file}"/>
              <af:panelLabelAndMessage label="SUBMITTED BY:"
                                       binding="#{backingBeanScope.backing_Test.plam1}"
                                       id="plam1">
                <af:outputText value="#{securityContext.userName}"
                               binding="#{backingBeanScope.backing_Test.ot1}"
                               id="ot1"/>
              </af:panelLabelAndMessage>
              <af:inputText value="#{bindings.Userid.inputValue}"
                            label="#{bindings.Userid.hints.label}"
                            required="#{bindings.Userid.hints.mandatory}"
                            columns="#{bindings.Userid.hints.displayWidth}"
                            maximumLength="#{bindings.Userid.hints.precision}"
                            shortDesc="#{bindings.Userid.hints.tooltip}"
                            binding="#{backingBeanScope.backing_Test.it1}"
                            id="it1" rendered="false">
                <f:validator binding="#{bindings.Userid.validator}"/>
              </af:inputText>
              <af:panelGridLayout binding="#{backingBeanScope.backing_Test.pgl1}"
                                  id="pgl1">
                <af:gridRow marginTop="5px" marginBottom="5px" height="auto"
                            binding="#{backingBeanScope.backing_Test.gr1}"
                            id="gr1">
                  <af:gridCell marginStart="5px" width="auto"
                               binding="#{backingBeanScope.backing_Test.gc1}"
                               id="gc1">
                    <af:commandButton
                                      text="Submit"
                                      disabled="#{!bindings.Commit.enabled}"
                                      binding="#{backingBeanScope.backing_Test.cb2}"
                                      id="cb2"
                                      action="#{backingBeanScope.backing_Test.cb2_action}"/>
                  </af:gridCell>
                  <af:gridCell marginStart="1px" width="auto"
                               binding="#{backingBeanScope.backing_Test.gc2}"
                               id="gc2">
                    <af:commandButton text="Cancel"
                                      binding="#{backingBeanScope.backing_Test.cb4}"
                                      id="cb4"
                                      partialTriggers="pfl1" disabled="true"/>
                  </af:gridCell>
                </af:gridRow>
              </af:panelGridLayout>
              <af:panelGridLayout binding="#{backingBeanScope.backing_Test.pgl2}"
                                  id="pgl2">
                <af:gridRow marginTop="5px" marginBottom="5px" height="auto"
                            binding="#{backingBeanScope.backing_Test.gr2}"
                            id="gr2">
                  <af:gridCell marginStart="5px" width="auto"
                               binding="#{backingBeanScope.backing_Test.gc5}"
                               id="gc5">
                    <af:resetButton text="Clear All"
                                    binding="#{backingBeanScope.backing_Test.rb1}"
                                    id="rb1"/>
                  </af:gridCell>
                  <af:gridCell marginStart="1px" marginEnd="5px" width="auto"
                               binding="#{backingBeanScope.backing_Test.gc6}"
                               id="gc6">
                    <a href="mailto:noharinc.com?subject=NO HARM Observation Feedback">Mail</a>
                  </af:gridCell>
                </af:gridRow>
              </af:panelGridLayout>
              <f:facet name="footer">
              </f:facet>
            </af:panelFormLayout>
          </f:facet>
          <f:facet name="header"/>
          <f:facet name="end"/>
          <f:facet name="start">
            <af:group binding="#{backingBeanScope.backing_Test.g1}" id="g1">
              <af:decorativeBox binding="#{backingBeanScope.backing_Test.db1}"
                                id="db1" topHeight="180px">
                <f:facet name="center"/>
                <f:facet name="top">
                  <af:image source="/[email protected]" shortDesc="NoHarmLogo"
                            binding="#{backingBeanScope.backing_Test.i1}"
                            id="i1"/>
                </f:facet>
              </af:decorativeBox>
            </af:group>
          </f:facet>
          <f:facet name="branding"/>
          <f:facet name="copyright"/>
          <f:facet name="status"/>
        </af:pageTemplate>
      </af:form>
    </af:document>
  </f:view>
  <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_Test-->
</jsp:root>



Here is my java code snippet:

//Method to create blobdomain from selected file
    private BlobDomain createBlobDomain(UploadedFile file) {
        InputStream in = null;
        BlobDomain blobDomain = null;
        OutputStream out = null;
        try {
            in = file.getInputStream();
            blobDomain = new BlobDomain();
            out = blobDomain.getBinaryOutputStream();
            byte[] buffer = new byte[8192];
            int bytesRead = 0;
            while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
                out.write(buffer, 0, bytesRead);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.fillInStackTrace();
        }
        return blobDomain;
    }

//Action lsitener for submit button
    public String cb2_action() {
        BindingContainer bindings = getBindings();    
        OperationBinding operationBinding = bindings.getOperationBinding("Commit");  
        //Grab the file
        UploadedFile myfile = (UploadedFile)this.getFile();

        //Set the Attachment InputText field value to the blob domain generated
        FacesContext facesCtx = FacesContext.getCurrentInstance();
        Application app = facesCtx.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = facesCtx.getELContext();
        ValueExpression ve = elFactory.createValueExpression(elContext, "#{bindings.Attachment.inputValue}",Object.class);
        //set the Attachment value to the blobdomain contents before inserting into db
        ve.setValue(elContext,createBlobDomain(myfile));
      
        //Commit input into Database     
        Object result = operationBinding.execute();     
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
      
        //Display popup message
        FacesContext con = FacesContext.getCurrentInstance();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO,"Thank you for submitting your observation.","");
        con.addMessage("",message);
      
        return null;
    }


haha OMG finally got it to work thanks @Timo Hahn (idk why didn't you tag) and Cvele_new_account

After reading comments Timo again and blog and wire with cvele comment

Solution was to make sure my update of bindings is set correctly, then check the "Insert" for updating the after:

Tags: Java

Similar Questions

Maybe you are looking for