Save image – working with large objects in JPA with Hibernate

/, JPA/Save image – working with large objects in JPA with Hibernate
Note:
Maven dependencies used all over JPA tutorials same. Please follow "Setting up Project" section to understand about project configuration.
persistence.xml and other code files reused from How to Persist an Entity in data base using JPA?
Each Sample application from download includes SQL file also.

LOB – large objects in database :

  • Databases will provide data types to store large objects (LOBs) in columns, this types will allow gigabyte ranges.
  • LOBs come in two flavors in the database: character large objects, called CLOBs, and binary large objects, or BLOBs.
  • As their names imply, a CLOB column holds a large character sequence, and a BLOB column can store a large byte sequence.
  • Mostly CLOB is to store text based files and BLOB is to store media files like images, videos,mp3 etc..
  • Data type names may vary in different databases(Oracle, MySql etc..).
  • JPA provides @Lob annotation to work with Large objects.

Example Application :

Database table Structure :

User Entity :

Test Code :

Verify in database :

  • Open table data in mysql workbench –> Right click on PROFILE_PIC column –> Select “Open Value In Editor” –> Select “Image” from opened window. you can see saved image in PROFILE_PIC column. See below screen.
Download Application – JPA-Image.zip (25 KB)
2017-08-31T12:41:54+00:00 Categories: Hibernate, JPA|Tags: , , , , , |1 Comment

One Comment

  1. miki April 16, 2018 at 2:54 pm - Reply

    and what if you save huge files, i mean huge, huge files, like 2GB? it has to be loaded into your memory. your solution is not a solution.

Leave a Reply

%d bloggers like this: