<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How can i save bytearrays via the entityclass in a database?</title><link>https://answers.axonivy.com/questions/3478/how-can-i-save-bytearrays-via-the-entityclass-in-a-database</link><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I am trying to set up an entityclass with a postgres server. I need this database to store some images i upload with the primefaces &lt;code&gt;&amp;amp;lt; p:fileUpload/&amp;gt;&lt;/code&gt; tag.
With this tag the images are uploaded as a &lt;code&gt;UploadedFile&lt;/code&gt;, now I can access the contents via &lt;code&gt;getContents()&lt;/code&gt; and I will get the image as a Bytearray (byte[] in Java) .  &lt;/p&gt;
&lt;p&gt;Now I need to know how can i save this Byte Array via the entityclasses in my postgres database. Postgres allows the datatype &lt;code&gt;bytea&lt;/code&gt; for a column for this datatype, but if I add Bytearray as a type for the column in the entityclass AxonIvy throws this error: &lt;code&gt;The field type 'Binary' does not support persistence&lt;/code&gt;.  &lt;/p&gt;
&lt;p&gt;So my question is:&lt;br&gt;
Is there any possibility i can save bytearray or blobs on my postgres server via the entity class?&lt;br&gt;
What are all the classes which &lt;strong&gt;support&lt;/strong&gt; &lt;em&gt;persistence&lt;/em&gt;?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/3478/how-can-i-save-bytearrays-via-the-entityclass-in-a-database" rel="self"></atom:link><language>en</language><lastBuildDate>Wed, 24 Oct 2018 02:45:44 -0400</lastBuildDate><item><title>Answer by Christian Strebel</title><link>https://answers.axonivy.com/questions/3478/how-can-i-save-bytearrays-via-the-entityclass-in-a-database/3497</link><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;This is not possible with the Entity Class Editor.
But you can write your own Java Class:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;package partner.protal.database;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;

@Entity
public class NewsImages {

 @Id
 @GeneratedValue
 private Integer id;

 @Lob
 private byte[] imageValue;

 @Lob
 private String imageNews;

 public Integer getId() {
  return id;
 }

 public byte[] getImageValue() {
  return imageValue;
 }

 public void setImageValue(byte[] imageValue) {
  this.imageValue = imageValue;
 }

 public String getLongString() {
  return imageNews;
 }

 public void setLongString(String longString) {
  this.imageNews = longString;
 }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img alt="Java Entity Class in Designer" src="https://answers.axonivy.com/upfiles/inline731451795.png"&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Christian Strebel</dc:creator><pubDate>Wed, 24 Oct 2018 02:45:44 -0400</pubDate><guid>https://answers.axonivy.com/questions/3478/how-can-i-save-bytearrays-via-the-entityclass-in-a-database/3497</guid></item></channel></rss>