By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

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

P: 7
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.
Mar 13 '13 #1
Share this Question
Share on Google+
11 Replies


Expert 100+
P: 1,031
"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)....
Mar 16 '13 #2

P: 7
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.
Mar 18 '13 #3

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

Expand|Select|Wrap|Line Numbers
  1. package jpa.entities;
  2.  
  3. import java.io.Serializable;
  4. import javax.persistence.Basic;
  5. import javax.persistence.Column;
  6. import javax.persistence.Entity;
  7. import javax.persistence.Id;
  8. import javax.persistence.Lob;
  9. import javax.persistence.NamedQueries;
  10. import javax.persistence.NamedQuery;
  11. import javax.persistence.Table;
  12. import javax.validation.constraints.NotNull;
  13. import javax.validation.constraints.Size;
  14. import javax.xml.bind.annotation.XmlRootElement;
  15.  
  16. /**
  17.  *
  18.  * @author Rmwanta
  19.  */
  20. @Entity
  21. @Table(name = "directory")
  22. @XmlRootElement
  23. @NamedQueries({
  24.     @NamedQuery(name = "Directory.findAll", query = "SELECT d FROM Directory d"),
  25.     @NamedQuery(name = "Directory.findByName", query = "SELECT d FROM Directory d WHERE d.name = :name"),
  26.     @NamedQuery(name = "Directory.findByAddress", query = "SELECT d FROM Directory d WHERE d.address = :address")})
  27. public class Directory implements Serializable {
  28.     private static final long serialVersionUID = 1L;
  29.     @Id
  30.     @Basic(optional = false)
  31.     @NotNull
  32.     @Size(min = 1, max = 40)
  33.     @Column(name = "name")
  34.     private String name;
  35.     @Basic(optional = false)
  36.     @NotNull
  37.     @Size(min = 1, max = 40)
  38.     @Column(name = "address")
  39.     private String address;
  40.     @Lob
  41.     @Column(name = "picture")
  42.     private byte[] picture;
  43.  
  44.     public Directory() {
  45.     }
  46.  
  47.     public Directory(String name) {
  48.         this.name = name;
  49.     }
  50.  
  51.     public Directory(String name, String address) {
  52.         this.name = name;
  53.         this.address = address;
  54.     }
  55.  
  56.     public String getName() {
  57.         return name;
  58.     }
  59.  
  60.     public void setName(String name) {
  61.         this.name = name;
  62.     }
  63.  
  64.     public String getAddress() {
  65.         return address;
  66.     }
  67.  
  68.     public void setAddress(String address) {
  69.         this.address = address;
  70.     }
  71.  
  72.     public byte[] getPicture() {
  73.         return picture;
  74.     }
  75.  
  76.     public void setPicture(byte[] picture) {
  77.         this.picture = picture;
  78.     }
  79.  
  80.    @Override
  81.     public int hashCode() {
  82.         int hash = 0;
  83.         hash += (name != null ? name.hashCode() : 0);
  84.         return hash;
  85.     }
  86.  
  87.     @Override
  88.     public boolean equals(Object object) {
  89.         // TODO: Warning - this method won't work in the case the id fields are not set
  90.         if (!(object instanceof Directory)) {
  91.             return false;
  92.         }
  93.         Directory other = (Directory) object;
  94.         if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name))) {
  95.             return false;
  96.         }
  97.         return true;
  98.     }
  99.  
  100.     @Override
  101.     public String toString() {
  102.         return "jpa.entities.Directory[ name=" + name + " ]";
  103.     }
  104.  
  105. }
  106.  
  107.  
  108.  
  109.  
  110.  
  111. CREATE TABLE directory (
  112. name  VARCHAR (40)  NOT NULL,
  113. address    VARCHAR(40) NOT NULL,
  114. picture BLOB NOT NULL,
  115. CONSTRAINT pk_directory PRIMARY KEY (name)
  116. );        
  117.  
  118.  
  119. <?xml version='1.0' encoding='UTF-8' ?>
  120. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  121. <html xmlns="http://www.w3.org/1999/xhtml"
  122.       xmlns:h="http://java.sun.com/jsf/html">
  123.     <h:head>
  124.         <title>Facelet Title</title>
  125.         <h:outputStylesheet name="css/jsfcrud.css"/>
  126.     </h:head>
  127.     <h:body>
  128.         Hello from Faith Baptist Church
  129.         <br />
  130.         <h:link outcome="/directory/List" value="Show All Directory Items"/>
  131.     </h:body>
  132.  
  133. </html>
Let me know if you see anything that can help me.
Apr 2 '13 #4

10K+
P: 13,264
When do you get the error message and what is the full stacktrace that you get?
Apr 3 '13 #5

P: 7
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.
Apr 3 '13 #6

10K+
P: 13,264
Check your stacktrace, the error is more likely to be coming from your JSF page than from the database.
Apr 3 '13 #7

P: 7
I am having a brain block, how do i check my stack trace?
Apr 3 '13 #8

10K+
P: 13,264
In the server's log.
Apr 4 '13 #9

P: 7
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.ha.store.adapter.cache.ShoalBackingS toreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
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 EjbThreadPoolExecutor 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.enterprise.security.provider.PolicyWrapper .
INFO: SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRe alm] successfully created.
INFO: SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRe alm] successfully created.
INFO: SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate .CertificateRealm] 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.webservices.JAXWSContainer@49e448c2 doesn't support class com.sun.xml.ws.api.server.Module
INFO: WS00019: EJB Endpoint deployed
CalculatorWSApplication listening at address at http://Newlaptop:8080/CalulatorWS/CalulatorWS
INFO: WEB0671: Loading application [CalculatorWSApplication] at [/CalculatorWSApplication]
INFO: CORE10010: Loading application CalculatorWSApplication done in 9,579 ms
INFO: WEB0671: Loading application [CalculatorWSServletClient] at [/CalculatorWSServletClient]
INFO: CORE10010: Loading application CalculatorWSServletClient done in 1,161 ms
INFO: WEB0671: Loading application [CalculatorWSJSPClient] at [/CalculatorWSJSPClient]
INFO: CORE10010: Loading application CalculatorWSJSPClient 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/NetBeansProjects/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.enterprise.v3.admin.DynamicInterceptor@79d 6ab4e].
WARNING: JMX MBeanServer in use: [com.sun.enterprise.v3.admin.DynamicInterceptor@79d 6ab4e] from index [0]
WARNING: JMX MBeanServer in use: [com.sun.jmx.mbeanserver.JmxMBeanServer@1972c74a] from index [1]
INFO: EJB5181:Portable JNDI names for EJB MicroMarketFacadeREST: [java:global/CustomerDB/MicroMarketFacadeREST!service.MicroMarketFacadeRES T, java:global/CustomerDB/MicroMarketFacadeREST]
INFO: EJB5181:Portable JNDI names for EJB CustomerFacadeREST: [java:global/CustomerDB/CustomerFacadeREST!service.CustomerFacadeREST, java:global/CustomerDB/CustomerFacadeREST]
INFO: EJB5181:Portable JNDI names for EJB DiscountCodeFacadeREST: [java:global/CustomerDB/DiscountCodeFacadeREST, java:global/CustomerDB/DiscountCodeFacadeREST!service.DiscountCodeFacadeR EST]
INFO: Registering the Jersey servlet application, named org.netbeans.rest.application.config.ApplicationCo nfig, 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/NetBeansProjects/Church Directory/build/web/WEB-INF/classes/_Church_DirectoryPU login successful
WARNING: Multiple [2] JMX MBeanServer instances exist, we will use the server at index [0] : [com.sun.enterprise.v3.admin.DynamicInterceptor@79d 6ab4e].
WARNING: JMX MBeanServer in use: [com.sun.enterprise.v3.admin.DynamicInterceptor@79d 6ab4e] from index [0]
WARNING: JMX MBeanServer in use: [com.sun.jmx.mbeanserver.JmxMBeanServer@1972c74a] from index [1]
INFO: EJB5181:Portable JNDI names for EJB DirectoryFacade: [java:global/Church_Directory/DirectoryFacade, java:global/Church_Directory/DirectoryFacade!jpa.session.DirectoryFacade]
INFO: Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/Church_Directory'
INFO: Monitoring jndi:/server/Church_Directory/WEB-INF/faces-config.xml for modifications
INFO: WEB0671: Loading application [Church_Directory] at [/Church_Directory]
INFO: CORE10010: Loading application Church_Directory done in 4,592 ms
INFO: GlassFish Server Open Source Edition 3.1.2.2 (5) startup time : Felix (21,590ms), startup services(25,096ms), 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: JMXStartupService 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]
Apr 5 '13 #10

10K+
P: 13,264
Perform the action that makes the exception occur and check the logs after that.
Apr 6 '13 #11

P: 7
I will try that an let you know.
Apr 6 '13 #12

Post your reply

Sign in to post your reply or Sign up for a free account.