title: Storing Images in database with BLOB type
body: <p>I have a question. How to save the file in the database? I use Spring Boot for backend language and PostgreSQL database. I have a User entity, and there is "avatar" field:</p>
  
  <pre><code>@Lob
  @Column(name = "avatar", columnDefinition="BLOB")
  private byte[] avatar;
  
  @Lob
  @Basic(fetch = FetchType.LAZY)
  public byte[] getAvatar() {
     return avatar;
  }
  public void setAvatar(byte[] avatar) {
     this.avatar = avatar;
  }
  </code></pre>
  
  <p>When I first register a user, avatar is got to null and when I save my user to DB I get an error (InvalidDataAccessResourceUsageException) and this message:<br />
  <strong>ERROR: column "avatar" is of type jsonb but expression is of type oid<br />
  Hint: You will need to rewrite or cast the expression.
    Position: 173</strong>
  <br />
  What can I do to solve this issue?<br />
  How does Spring solves this problem and saves files in DB?<br />
  What is the best practice?</p>