Mapping BLOBs & CLOBs with JPA and Hibernate

preview_player
Показать описание

Especially the lazy-loading trick is a mapping that most developers are surprised about and that I have used with great success in various client projects.
But before we start, if this is your first time here, and you want to learn how to create your entity mappings with ease, build incredible efficient persistence layers with Hibernate and all types of other Java persistence related stuff, start now by subscribing and clicking the bell, so you don't miss anything.

Databases use the data types binary large object aka BLOB and character large object aka CLOB to store large objects, like images and very long texts. JPA and Hibernate provide two kinds of mappings for these types.

You can choose if you want to:

Materialize the LOB and map it to a byte[] or a String. This mapping is defined by the JPA specification and prioritizes ease of use over performance.

If you like this video, please give me your thumbs up and share it with your friends and co-workers.

Like my channel? Subscribe!

Join the free Member Library:

Want to connect with me?

#JPA #Hibernate #blob #clob
Рекомендации по теме
Комментарии
Автор

Thanks for this nice video.
2:15 Mapping a LOB to String or byte[]
3:51 Mapping LOB to java.sql.Clob or Blob. Hibernate specific mapping, requires usage of BlobProxy.
5:56 Lazy loading of LOBs. To "guarantee lazy loading" of the String / byte[] approach, put LOB to separate entity, @OneToOne @MapsId, and on demand manually navigate to the subentity containing the LOB.

lbreuss
Автор

Very usefull, thx - Muy util, gracias

CHIP_X
Автор

Good night. I have an Oracle database with a table with 4 Clob-type fields. The CRUD (Read, Modify and Delete) works correctly except for the create shows me the following error when I use Postman. How is the correct syntax in Spring to insert clob type data without showing me the following error?:

023-06-13 19:21:15.353 ERROR 6556 --- [nio-8084-exec-1] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is could not extract ResultSet; SQL [n/a]; nested exception is could not extract ResultSet] with root cause

ORA-00932: tipos de dato inconsistentes: se esperaba - se ha obtenido CLOB.

hangofox
Автор

Could you share some mybatis tutorials please?

adbyte
Автор

Hi, what about BFILES type column from Oracle, how to map that type on entities or there are workarounds? ... thanks !

JonathanMiranda
Автор

Sir, can you teach security approaches in Hibernate?

prakashtayade
Автор

Your BlobProxy.generateProxy() is not working for me with IBM db2 database. Earlier I have used Hibernate.createBlob() and it was working fine with hibernate 3. But recently I have updated my hibernate version to 5.4.18. I can't get any alternative of Hibernate.createBlob() in hibernate 5. I am getting Sqlcode=-302 error while persisting blob data into database. But with the same data older code Hibernate.createBlob() is working absolutely fine. Please advise.

riteshch.roymoulick
Автор

Make a tuturial how to save img into a database

davidsalleyezonme