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);