JPA: should I store a BLOB in the same table with fetch Lazy or should I store it to another table and fetch lazy the one to one relationship
blob, java, jpa
Solution
As far as I know, the first does not work with Hibernate and EclipseLink as JPA providers. LAZY is a hint for the provider, these will load eagerly without reporting an error or warning.
OneToOne association will be lazy only if class weaving is enabled, otherwise it will not help either.
I have done it using a completely separate table called LazyBlob, with attributes "entity" and "id", and wrote an utility class to fetch lob lazily from this table.
Problem
I have a table `Image` that hold the image information. I also want to store the image itself. So should I 1.Store the Blob in the same image table and fetch it lazy as below ``` @Basic(optional = false, fetch = FetchType.LAZY) @Lob @Column(name = "IMAGE_BLOB", length=100000) //This will generate MEDIUMBLOB private byte[] imageBlob; ``` Or 2.Create a another table `ImageBlob` with `OneToOne` relationship with `Image`, and fetch lazy the relationship ``` @OneToOne(cascade = CascadeType.ALL, mappedBy = "image", fetch=FetchType.LAZY) private ImageBlob imageBlob; ``` Are these two technique the same in term of performance?