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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With