2

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.