Trying to use a blob data type to add an image to a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wantar20
    New Member
    • Mar 2013
    • 7

    Trying to use a blob data type to add an image to a database

    I am currently trying to build a crud application to load name, address and picture data for members of an organization. I have the database set up, but when I run the application I get a null converter error for the blob data. What do I need do to get the application to work. I can send or post the application if more information is needed.
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    "I am currently trying to build a crud application"
    In what language are you trying to do this?

    "I get a null converter error for the blob data"
    can you copy a piece of the code here, plus the exact error message(s)....

    Comment

    • wantar20
      New Member
      • Mar 2013
      • 7

      #3
      I am using java. I will get on my laptop and run the application so I can copy some code as that is where I am developing my application.

      Comment

      • wantar20
        New Member
        • Mar 2013
        • 7

        #4
        Sorry this took so long, my laptop crashed and I needed to get it fixed. here is some code from my application.

        Code:
        package jpa.entities;
        
        import java.io.Serializable;
        import javax.persistence.Basic;
        import javax.persistence.Column;
        import javax.persistence.Entity;
        import javax.persistence.Id;
        import javax.persistence.Lob;
        import javax.persistence.NamedQueries;
        import javax.persistence.NamedQuery;
        import javax.persistence.Table;
        import javax.validation.constraints.NotNull;
        import javax.validation.constraints.Size;
        import javax.xml.bind.annotation.XmlRootElement;
        
        /**
         *
         * @author Rmwanta
         */
        @Entity
        @Table(name = "directory")
        @XmlRootElement
        @NamedQueries({
            @NamedQuery(name = "Directory.findAll", query = "SELECT d FROM Directory d"),
            @NamedQuery(name = "Directory.findByName", query = "SELECT d FROM Directory d WHERE d.name = :name"),
            @NamedQuery(name = "Directory.findByAddress", query = "SELECT d FROM Directory d WHERE d.address = :address")})
        public class Directory implements Serializable {
            private static final long serialVersionUID = 1L;
            @Id
            @Basic(optional = false)
            @NotNull
            @Size(min = 1, max = 40)
            @Column(name = "name")
            private String name;
            @Basic(optional = false)
            @NotNull
            @Size(min = 1, max = 40)
            @Column(name = "address")
            private String address;
            @Lob
            @Column(name = "picture")
            private byte[] picture;
        
            public Directory() {
            }
        
            public Directory(String name) {
                this.name = name;
            }
        
            public Directory(String name, String address) {
                this.name = name;
                this.address = address;
            }
        
            public String getName() {
                return name;
            }
        
            public void setName(String name) {
                this.name = name;
            }
        
            public String getAddress() {
                return address;
            }
        
            public void setAddress(String address) {
                this.address = address;
            }
        
            public byte[] getPicture() {
                return picture;
            }
        
            public void setPicture(byte[] picture) {
                this.picture = picture;
            }
        
           @Override
            public int hashCode() {
                int hash = 0;
                hash += (name != null ? name.hashCode() : 0);
                return hash;
            }
        
            @Override
            public boolean equals(Object object) {
                // TODO: Warning - this method won't work in the case the id fields are not set
                if (!(object instanceof Directory)) {
                    return false;
                }
                Directory other = (Directory) object;
                if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name))) {
                    return false;
                }
                return true;
            }
        
            @Override
            public String toString() {
                return "jpa.entities.Directory[ name=" + name + " ]";
            }
            
        }
        
        
        
        
        
        CREATE TABLE directory (
        name  VARCHAR (40)  NOT NULL,
        address	VARCHAR(40) NOT NULL,
        picture BLOB NOT NULL,
        CONSTRAINT pk_directory PRIMARY KEY (name)
        );        
        
        
        <?xml version='1.0' encoding='UTF-8' ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml"
              xmlns:h="http://java.sun.com/jsf/html">
            <h:head>
                <title>Facelet Title</title>
                <h:outputStylesheet name="css/jsfcrud.css"/>
            </h:head>
            <h:body>
                Hello from Faith Baptist Church
                <br />
                <h:link outcome="/directory/List" value="Show All Directory Items"/>
            </h:body>
        
        </html>
        Let me know if you see anything that can help me.
        Last edited by Rabbit; Apr 2 '13, 10:22 PM. Reason: Please use code tags when posting code.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          When do you get the error message and what is the full stacktrace that you get?

          Comment

          • wantar20
            New Member
            • Mar 2013
            • 7

            #6
            I get the "Null Coverter Error" when trying to add a picture to the database. I will have to run the application again and look at the stack trace to see what it is.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Check your stacktrace, the error is more likely to be coming from your JSF page than from the database.

              Comment

              • wantar20
                New Member
                • Mar 2013
                • 7

                #8
                I am having a brain block, how do i check my stack trace?

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  In the server's log.

                  Comment

                  • wantar20
                    New Member
                    • Mar 2013
                    • 7

                    #10
                    I think this is the stack trace from the server. I don't see anything that would be causing the problem.

                    INFO: Running GlassFish Version: GlassFish Server Open Source Edition 3.1.2.2 (build 5)
                    INFO: Registered org.glassfish.h a.store.adapter .cache.ShoalBac kingStoreProxy for persistence-type = replicated in BackingStoreFac toryRegistry
                    INFO: Grizzly Framework 1.9.50 started in: 115ms - bound to [0.0.0.0:3700]
                    INFO: Grizzly Framework 1.9.50 started in: 171ms - bound to [0.0.0.0:8080]
                    INFO: Grizzly Framework 1.9.50 started in: 134ms - bound to [0.0.0.0:8181]
                    INFO: Grizzly Framework 1.9.50 started in: 124ms - bound to [0.0.0.0:4848]
                    INFO: Grizzly Framework 1.9.50 started in: 102ms - bound to [0.0.0.0:7676]
                    INFO: Created EjbThreadPoolEx ecutor with thread-core-pool-size 16 thread-max-pool-size 32 thread-keep-alive-seconds 60 thread-queue-capacity 2147483647 allow-core-thread-timeout false
                    INFO: SEC1002: Security Manager is OFF.
                    INFO: SEC1010: Entering Security Startup Service
                    INFO: SEC1143: Loading policy provider com.sun.enterpr ise.security.pr ovider.PolicyWr apper.
                    INFO: SEC1115: Realm [admin-realm] of classtype [com.sun.enterpr ise.security.au th.realm.file.F ileRealm] successfully created.
                    INFO: SEC1115: Realm [file] of classtype [com.sun.enterpr ise.security.au th.realm.file.F ileRealm] successfully created.
                    INFO: SEC1115: Realm [certificate] of classtype [com.sun.enterpr ise.security.au th.realm.certif icate.Certifica teRealm] successfully created.
                    INFO: SEC1011: Security Service(s) Started Successfully
                    INFO: WS10010: Web service endpoint deployment events listener registered successfully.
                    INFO: WEB0169: Created HTTP listener [http-listener-1] on host/port [0.0.0.0:8080]
                    INFO: WEB0169: Created HTTP listener [http-listener-2] on host/port [0.0.0.0:8181]
                    INFO: WEB0169: Created HTTP listener [admin-listener] on host/port [0.0.0.0:4848]
                    INFO: WEB0171: Created virtual server [server]
                    INFO: WEB0171: Created virtual server [__asadmin]
                    INFO: WEB0172: Virtual server [server] loaded default web module []
                    WARNING: Container org.glassfish.w ebservices.JAXW SContainer@49e4 48c2 doesn't support class com.sun.xml.ws. api.server.Modu le
                    INFO: WS00019: EJB Endpoint deployed
                    CalculatorWSApp lication listening at address at http://Newlaptop:8080/CalulatorWS/CalulatorWS
                    INFO: WEB0671: Loading application [CalculatorWSApp lication] at [/CalculatorWSApp lication]
                    INFO: CORE10010: Loading application CalculatorWSApp lication done in 9,579 ms
                    INFO: WEB0671: Loading application [CalculatorWSSer vletClient] at [/CalculatorWSSer vletClient]
                    INFO: CORE10010: Loading application CalculatorWSSer vletClient done in 1,161 ms
                    INFO: WEB0671: Loading application [CalculatorWSJSP Client] at [/CalculatorWSJSP Client]
                    INFO: CORE10010: Loading application CalculatorWSJSP Client done in 508 ms
                    INFO: HV000001: Hibernate Validator 4.3.0.Final
                    INFO: EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
                    INFO: file:/C:/Users/Rmwanta/Documents/NetBeansProject s/CustomerDB/build/web/WEB-INF/classes/_CustomerDBPU login successful
                    WARNING: Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterpr ise.v3.admin.Dy namicIntercepto r@79d6ab4e].
                    WARNING: JMX MBeanServer in use: [com.sun.enterpr ise.v3.admin.Dy namicIntercepto r@79d6ab4e] from index [0]
                    WARNING: JMX MBeanServer in use: [com.sun.jmx.mbe anserver.JmxMBe anServer@1972c7 4a] from index [1]
                    INFO: EJB5181:Portabl e JNDI names for EJB MicroMarketFaca deREST: [java:global/CustomerDB/MicroMarketFaca deREST!service. MicroMarketFaca deREST, java:global/CustomerDB/MicroMarketFaca deREST]
                    INFO: EJB5181:Portabl e JNDI names for EJB CustomerFacadeR EST: [java:global/CustomerDB/CustomerFacadeR EST!service.Cus tomerFacadeREST , java:global/CustomerDB/CustomerFacadeR EST]
                    INFO: EJB5181:Portabl e JNDI names for EJB DiscountCodeFac adeREST: [java:global/CustomerDB/DiscountCodeFac adeREST, java:global/CustomerDB/DiscountCodeFac adeREST!service .DiscountCodeFa cadeREST]
                    INFO: Registering the Jersey servlet application, named org.netbeans.re st.application. config.Applicat ionConfig, at the servlet mapping, /webresources/*, with the Application class of the same name
                    INFO: WEB0671: Loading application [CustomerDB] at [/CustomerDB]
                    INFO: CORE10010: Loading application CustomerDB done in 7,642 ms
                    INFO: EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
                    INFO: file:/C:/Users/Rmwanta/Documents/NetBeansProject s/Church Directory/build/web/WEB-INF/classes/_Church_Directo ryPU login successful
                    WARNING: Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterpr ise.v3.admin.Dy namicIntercepto r@79d6ab4e].
                    WARNING: JMX MBeanServer in use: [com.sun.enterpr ise.v3.admin.Dy namicIntercepto r@79d6ab4e] from index [0]
                    WARNING: JMX MBeanServer in use: [com.sun.jmx.mbe anserver.JmxMBe anServer@1972c7 4a] from index [1]
                    INFO: EJB5181:Portabl e JNDI names for EJB DirectoryFacade : [java:global/Church_Director y/DirectoryFacade , java:global/Church_Director y/DirectoryFacade !jpa.session.Di rectoryFacade]
                    INFO: Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/Church_Director y'
                    INFO: Monitoring jndi:/server/Church_Director y/WEB-INF/faces-config.xml for modifications
                    INFO: WEB0671: Loading application [Church_Director y] at [/Church_Director y]
                    INFO: CORE10010: Loading application Church_Director y done in 4,592 ms
                    INFO: GlassFish Server Open Source Edition 3.1.2.2 (5) startup time : Felix (21,590ms), startup services(25,096 ms), total(46,686ms)
                    INFO: WEB0169: Created HTTP listener [http-listener-1] on host/port [0.0.0.0:8080]
                    INFO: Grizzly Framework 1.9.50 started in: 4ms - bound to [0.0.0.0:8080]
                    INFO: JMX005: JMXStartupServi ce had Started JMXConnector on JMXService URL service:jmx:rmi ://Newlaptop:8686/jndi/rmi://Newlaptop:8686/jmxrmi
                    INFO: WEB0169: Created HTTP listener [http-listener-2] on host/port [0.0.0.0:8181]
                    INFO: Grizzly Framework 1.9.50 started in: 3ms - bound to [0.0.0.0:8181]

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Perform the action that makes the exception occur and check the logs after that.

                      Comment

                      • wantar20
                        New Member
                        • Mar 2013
                        • 7

                        #12
                        I will try that an let you know.

                        Comment

                        Working...