title: How to save an image to mysql database using hibernate in netbeans and how to and retrieve it and show
body: <p>I have already saved the image using this code in servlet. productSubType and Product are tables in my database. Foreign key of <code>ProductSubType</code> is included in Product table.</p>
  <pre><code>    try (PrintWriter out = response.getWriter()) {
  
          Session s = connection.NewHibernateUtil.getSessionFactory().openSession();
  
          String name = request.getParameter(&quot;fupload&quot;);
          File f = new File(getServletContext().getRealPath(&quot;/&quot;)+&quot;&quot;+name);
          ProductSubType p_Stype = new ProductSubType();
          p_Stype=(ProductSubType) s.load(ProductSubType.class, Integer.parseInt(request.getParameter(&quot;p_combo&quot;)));
         
          Product p = new Product();
          p.setPName(request.getParameter(&quot;p_name&quot;));           
          p.setKeyWords(request.getParameter(&quot;keywords&quot;));           
          p.setQuality(request.getParameter(&quot;width&quot;)+&quot;,&quot;+request.getParameter(&quot;height&quot;));           
          p.setProductSubType(p_Stype);           
          p.setProduct(f.getPath());           
          p.setPrice(request.getParameter(&quot;price&quot;));
         
          s.save(p);
          s.beginTransaction().commit();
          response.sendRedirect(&quot;add_image.jsp&quot;);
      }
  </code></pre>
  <p>This is my Product class</p>
  <pre><code> public class Product  implements java.io.Serializable {
  
   private Integer idproduct;
   private ProductSubType productSubType;
   private String PName;
   private String quality;
   private String product;
   private String price;
   private String keyWords;
   private Set&lt;Upload&gt; uploads = new HashSet&lt;Upload&gt;(0);
   private Set&lt;InvoiceHasProduct&gt; invoiceHasProducts = new HashSet&lt;InvoiceHasProduct&gt;(0);
   private Set&lt;CartHasProduct&gt; cartHasProducts = new HashSet&lt;CartHasProduct&gt;(0);
   private Set&lt;Download&gt; downloads = new HashSet&lt;Download&gt;(0);
  
  public Product() {
  }
  
  public Product(ProductSubType productSubType) {
      this.productSubType = productSubType;
  }
  
  public Product(ProductSubType productSubType, String PName, String quality, String product, String price, String keyWords, Set&lt;Upload&gt; uploads, Set&lt;InvoiceHasProduct&gt; invoiceHasProducts, Set&lt;CartHasProduct&gt; cartHasProducts, Set&lt;Download&gt; downloads) {
     this.productSubType = productSubType;
     this.PName = PName;
     this.quality = quality;
     this.product = product;
     this.price = price;
     this.keyWords = keyWords;
     this.uploads = uploads;
     this.invoiceHasProducts = invoiceHasProducts;
     this.cartHasProducts = cartHasProducts;
     this.downloads = downloads;
  }
  
  public Integer getIdproduct() {
      return this.idproduct;
  }
  
  public void setIdproduct(Integer idproduct) {
      this.idproduct = idproduct;
  }
  public ProductSubType getProductSubType() {
      return this.productSubType;
  }
  
  public void setProductSubType(ProductSubType productSubType) {
      this.productSubType = productSubType;
  }
  
  public String getPName() {
      return this.PName;
  }
  
  public void setPName(String PName) {
      this.PName = PName;
  }
  
  public String getQuality() {
      return this.quality;
  }
  
  public void setQuality(String quality) {
      this.quality = quality;
  }
  
  public String getProduct() {
      return this.product;
  }
  
  public void setProduct(String product) {
      this.product = product;
  }
  
  public String getPrice() {
      return this.price;
  }
  
  public void setPrice(String price) {
      this.price = price;
  }
  
  public String getKeyWords() {
      return this.keyWords;
  }
  
  public void setKeyWords(String keyWords) {
      this.keyWords = keyWords;
  }
  
  public Set&lt;Upload&gt; getUploads() {
      return this.uploads;
  }
  
  public void setUploads(Set&lt;Upload&gt; uploads) {
      this.uploads = uploads;
  }
  
  public Set&lt;InvoiceHasProduct&gt; getInvoiceHasProducts() {
      return this.invoiceHasProducts;
  }
  
  public void setInvoiceHasProducts(Set&lt;InvoiceHasProduct&gt; invoiceHasProducts) {
      this.invoiceHasProducts = invoiceHasProducts;
  }
  
  public Set&lt;CartHasProduct&gt; getCartHasProducts() {
      return this.cartHasProducts;
  }
  
  public void setCartHasProducts(Set&lt;CartHasProduct&gt; cartHasProducts) {
      this.cartHasProducts = cartHasProducts;
  }
  
  public Set&lt;Download&gt; getDownloads() {
      return this.downloads;
  }
  
  public void setDownloads(Set&lt;Download&gt; downloads) {
      this.downloads = downloads;
  }
  
  }
  </code></pre>
  <p>The image is saved. There are no errors in saving. But the path of the image is saved to the database as--&gt;E:...\ProjectName\build\web\190847.png</p>
  <p>Is it correct? and if so, how can I retrieve the images and show them in a page?</p>