title: How to put JSONB throught Postgres database with JPA
body: <p>I am trying to build an REST application using Jersey, Gson, JPA and I would like to put a JSON object to <a href="https://www.postgresql.org/docs/9.4/static/datatype-json.html" rel="nofollow noreferrer">JSON or JSONB</a> database field into Postgres.</p>
  
  <p>I tried to do something like this : <a href="https://stackoverflow.com/questions/39830842/how-to-use-postgres-jsonb-datatype-with-jpa#answer-39885334">How to use Postgres JSONB datatype with JPA?</a> but my table see a 'VARCHAR' type instead of 'JSONB'.</p>
  
  <p>My Entity : </p>
  
  <pre><code>@Entity
  @Table(name = "votes")
  
  public class Votes {
  
  @Id
  @GeneratedValue
  private int id;
  private int idSocialChoice;
  
  @Convert(converter=JsonConverter.class)
  private JsonObject vote;
  
  public Votes() {
  }
  
  public JsonObject getVote() {
      return vote;
  }
  
  public void setVote(JsonObject vote) {
      this.vote = vote;
  }
  
  public int getIdSocialChoice() {
      return idSocialChoice;
  }
  
  public void setIdSocialChoice(int idSocialChoice) {
      this.idSocialChoice = idSocialChoice;
  }
  </code></pre>
  
  <p>How i insert my entity :</p>
  
  <pre><code>Votes votes0 = new Votes();
  votes0.setIdSocialChoice(3);
  
  JsonObject object = Json.createObjectBuilder().build();
  votes0.setVote(object);
  
  List&lt;Votes&gt; listvotes = new ArrayList&lt;Votes&gt;();
  listvotes.add(votes0);
  
  ModelEntities.insertVotes(listvotes);
  </code></pre>
  
  <p>Method insertVotes :</p>
  
  <pre><code>public static void insertVotes(List&lt;Votes&gt; animalList) {
  
      CrudServiceBean crudServiceBean = new CrudServiceBean(CrudServiceBean.PU_DB);
      crudServiceBean.newTransaction();
  
      for(Votes votes : animalList)
          crudServiceBean.create(votes);
  
      crudServiceBean.commit();
  
      crudServiceBean.closeTransaction();
  
  }
  </code></pre>
  
  <p>Method create of crudServiceBean.create :</p>
  
  <pre><code>public  &lt;T&gt; T create(T t) {
      this.em.persist(t);
      this.em.flush();
      this.em.refresh(t);
      return t;
  }
  </code></pre>
  
  <p>My JPA provider create my the schema like this (createDDL_ddlGeneration.sql) : </p>
  
  <pre><code>CREATE TABLE votes (ID INTEGER NOT NULL, IDSOCIALCHOICE INTEGER, VOTE VARCHAR(255), PRIMARY KEY (ID))
  </code></pre>
  
  <p>I would also avoid to use Hibernate.</p>
  
  <p>Thank you.</p>