A binary large object stores a large binary value, such as an image, in a database column. The Java property type determines how Hibernate maps and loads that value. section 6.3.1
For an entity’s image property, the main mapping choices are:
- Use byte[] for the default VARBINARY mapping; the native column type depends on the SQL dialect and declared length. section 6.3.1
- Add @Lob to byte[] to map it as a BLOB. The bytes still load when the entity loads unless field-access interception is enabled through bytecode instrumentation. section 6.3.1
- Use java.sql.Blob for lazy loading without bytecode instrumentation; obtain its binary data through a stream. section 6.3.1
Item item = em.find(Item.class, ITEM_ID); InputStream imageDataStream = item.getImageBlob().getBinaryStream(); #1 ByteArrayOutputStream outStream = new ByteArrayOutputStream(); #2 StreamUtils.copy(imageDataStream, outStream); #3 byte[] imageBytes = outStream.toByteArray();
The stream-reading example shows how to obtain image bytes from a Blob property after finding the entity. section 6.3.1

