@Lob Annotation in Hibernate Example

@Lob Annotation in Hibernate

In this tutorial, you will learn about simple implementation of @Lob annotation in hibernate example. This particular example were tested with MySQL database server environment and all programs and output has been shared in the same post.

The @Lob stands for Large Object. Sometimes we may have to store the large amount of character to specific column in the table (eg: Project Description, Product Description, Book Information and etc.). When we have the string field in a entity class, The hibernate framework will create the table with string fields as varchar datatype with maximum value of 255 (ie: bookDescription varchar(255)) by default. But they are may not be useful when we wants to store large information(more characters) to the specific column in a table.

If we add the @LOB annotation to string field it will be changed as longtext from the varchar datatype in table, then we can able to store the large amount of character to specific column. The following steps contains simple implementation of @Lob annotation in hibernate.

Project Structure

@LOB Annotation in Hibernate

1) Getting the session from session factory

2) Entity class with @Lob annotation

3) Persisting the book entity to the database table

Download Source Code

you can download the entire source code here


@LOB Annotation in Hibernate

@LOB Annotation in Hibernate


1. JPA API Documentation
2. @Lob Annotation Documentation