Categories
Java SQL

Java Optional in Hibernate 6 entity support

Support Java Optional in Hibernate 6 entity, thanks to the Lib Custom library, a wrapper that simplifies calls to Byte Buddy library In this tuto we use the functional option class: OptionF, but with little changes you can use any other option class, such as Optional 1) Add lib-custom to your pom.xml dependencies Lib-custom is […]

Categories
Java

Customize external Java library functions, simple Byte Buddy

Customize external Java library functions simple Byte Buddy. Lib Custom is a wrapper around Byte Buddy that allows to customize external Java libraries very easily: https://github.com/jleblanc64/lib-custom 1) Add dependency to your pom.xml 2) Modify the external library class function Let’s say you have an external library with following class and function: We want to override […]

Categories
AWS Java SQL

Backup AWS MySQL, mount the backup locally and explore with SQuirreL

In this tutorial, we will backup an AWS RDS MySQL database as a dump, then we will mount the dump locally using a MySQL Testcontainers. Finally, we will explore the local backup content and schema, using SQuirreL. 1) Backup the AWS MySQL database We need an EC2 instance that has access to the database. For […]

Categories
AWS Docker Java

AWS Elastic BeanStalk + Spring boot + Hibernate + MySQL

In this tutorial, we explain how to build a docker image that contains a Java Spring Boot REST API and JPA Hibernate ORM, to connect to an AWS RDS MySQL database. 1) Get started You can use our previous tutorial that explains how to use Spring Boot with Hibernate. The only things we will add […]

Categories
Java

Minimal, fully running Spring Boot REST API with Java Hibernate and MySQL

In this tutorial, we explain how to run a minimal Spring Boot CRUD REST application, with Hibernate ORM and a MySQL database. We also write unit tests, to check the CRUD operations with the API. We do all this in less than 200 lines of code. This tutorial is useful to get started for any […]

Categories
Java

Dynamic database connection properties for Spring Boot

How to set Spring Boot database connection properties dynamically, in the application main. Also we explain the priority order between static and dynamic properties. 1) The usual static way Usually, Spring Boot properties are set in the application properties file, which has following path: src/main/resources/application.properties and following content: 2) The dynamic programmatic way It is […]

Categories
Bash Java

Public and private PGP keys with Java BouncyCastle, in PEM format

We explain how to generate public and private PGP keys, in Java, using the BouncyCastle library. Then, we store the keys in PEM base64 files, and add the keys to our GPG keyring. Finally, we test the keys by encrypting and decrypting a text file using the Linux gpg command line interface (CLI). 1) BouncyCastle […]

Categories
GCP Java

Google search console Java API, with OAuth code flow or Service Account

In this tutorial, we explain how to connect and use the Google search console Java API. We first connect to the API using either the OAuth authorization code flow, or a GCP Service Account. In particular, we describe how to save a StoredCredential on disk, and how to get a refresh token by setting accessType […]

Categories
AWS Java

Fast delete all the objects in a S3 bucket with Java AWS SDK

In this article, we explain how to fast delete all the objects in a given AWS S3 bucket. We will use batch deletes with the Java AWS SDK. 1) Java AWS SDK dependency First, we need to add the Java AWS dependency to our pom.xml: 2) Gather all the S3 objects keys in the bucket […]

Categories
Java

Read all image metadata with Java

How to read all the metadata of an image (image format, width and height) in Java. We will the use the awesome metadata-extractor library. 1) Add the dependency Add the following dependency to your pom.xml: 2) Read the image metadata For this example, we will use an image from our own website, eazytutorial.com, but you […]