1

I'm trying to store images as binaries into a Postgres database with Java JPA.
I tried to use @Entity class with Blob field, which works well, but many people use just byte[] arrays. see #1, #2, etc.

What are the advantages and disadvantages of both?
When one should be preferred over another?

@Entity
public class ImageEntity {
    @Id
    private UUID id;
    @Lob
    @Fetch(FetchMode.JOIN)
    private Blob data;
}

// create Blob:         
byte[] myBytes = ...
Blob blob = new SerialBlob(myBytes);
Viacheslav Shalamov
  • 4,149
  • 6
  • 44
  • 66
  • 1
    perfomance of `Blob`? [Mapping BLOBs and CLOBs with Hibernate and JPA](https://thoughts-on-java.org/mapping-blobs-and-clobs-with-hibernate-and-jpa/) – sudipn Dec 21 '19 at 18:15

0 Answers0