Spring Hibernate JPA – Upload/Download File/Image to PostgreSQL with @Lob Example

In the tutorial, we guide how to upload/download file to PostGreSQL using Spring Hibernate JPA with @Lob annotation.

Technologies

– Java 1.8
– Maven 3.6.1
– Spring Tool Suite – Version 3.9.4.RELEASE
– PostgreSQL 9.6
– Spring Boot – 2.0.2.RELEASE

Goal

– We create a SpringBoot project as below structure:

-> Run & Check results:

SpringJPA-Upload-Download-File-Image-to-PostGreSQL-tables

Practice

Step to do
– Create SpringBoot project
– Create Data Model
– Create JPA Repository
– Implement Client to Download/Upload files
– Configure JPA connection

Create SpringBoot project

Using SpringToolSuite to create a SpringBoot project with dependencies:

Create Data Model

Create JPA Repository

Implement Client to Download/Upload files

Configure JPA connection

– Open application.properties file, add connection setting:

Why use setting spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false?

-> If you don’t have above setting, you will meet exception’s logs as below:

-> Above exception is not a real exception because Hibernate just tries to get some meta information from the database when loading.
So you can use spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false to disable it.

Sourcecode

SpringJpaSaveFiles2PostgreSQL

By grokonez | May 28, 2018.



Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*