Hibernate JPA and PostgreSQL: change type from String to text (@Lob)

In existing table with data populated, changing the column type from string to text requires some migration. For large data type, Postgres stores the data in a separate location and just references it by using an ID. This means that, until then, column data would be a string content and after the change, it would…

gRPC Spring Boot Server with Oauth2 (Keycloak)

This post will describe, in shortest steps, the configuration needed to get spring boot grpc server secured with oauth2 tokens, in my case with Keycloak. Resources: OAuth 2.0 Resource Server JWT gRPC Spring Boot Starter Server security configuration Postman gRPC My demo project can be found at github. Server code has been updated to have…

Hexagonal Architecture With SpringBoot

I have been trying to create a clean hexagonal architecture example with SpringBoot. More complex approaches are possible, by introducing the CQRS into the equation, but I believe that just over complicates the architecture and if there is no really good reason for it, I’d avoid it. There are a couple of examples out there…

Spring Boot JPA Test Splice

Here is a small example that: Uses @DataJpaTest annotation to bring in only configuration relevant for JPA tests (entities, repos etc…) Uses @TestMethodOrder(MethodOrderer.OrderAnnotation.class) and @Order annotations to enforce order of method execution Uses @ComponentScan(basePackages = {“tech.dimitar.rosdjpaint.bootstrap”}) annotation to bring in the component that bootstraps the data Uses @Commit annotation on test to enforce transaction does…

Initialize a Database Using Hibernate – profile and db based

You want to initialize a database with different data depending on the data source? Should be straight forward: https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.data-initialization Spring Boot can automatically create the schema (DDL scripts) of your JDBC DataSource or R2DBC ConnectionFactory and initialize it (DML scripts). It loads SQL from the standard root classpath locations: schema.sql and data.sql, respectively. In addition,…

Distributed lock on GCP Datastore

So, I needed a distributed lock on the GCP Datastore. In theory, it is all very simple: Get the lock Do what you need to do Release the lock And, when I started thinking about it, it became clear that I need to have some kind of transaction mechanism in order to obtain the lock….

Thread.sleep()

To continue with writing integration tests. When testing asynchronous operations, such as sending message to a queue, waiting for a response and completing some task, we need to introduce some kind of wait time in the test. Instead of using Thread.sleep(), we can use something called Awaitility… Documentation is pretty self explanatory… Testing asynchronous systems…