Posts

What you need to know before writing a query with the JPA Criteria API and Hibernate

Image
TL;DR : JPA (2.*) does not support the "UNION" sql operation. JPA does not require a persistence provider to support Right outer joins or Right outer fetch joins, to be compliant with its API. Hibernate (5.*) does not support Right outer joins or Right outer fetch joins. Last week I bumped heads with JPA (2.2) and Hibernate (5.4). I had to write a search query on some tangled datastructures.  I tend to write queries out on paper first, for clarity. Here are some takeaways, while I wasted some scrap paper on the iterations. State of the UNION in JPA I ended up with a union of 3 queries. The moment that I wanted to get dirty with JPA to create a CriteriaQuery I hit the first snag. JPA 2.0 does not support the sql "UNION" operation. One does not simply join with JPA and Hibernate The next step was to rewrite the set of unions to a set of joins. 5 (+ 2 shared) Left joins and 4 right outer joins on I had one single unified query. I quickly glanced in my ID...

IT; how we see each other

Image
As developers, many of us work together with colleagues from other disciplines. It's good to realize that both disciplines and developers can have a wide range of views on software development. Here are some graphic examples. source: https://www.reddit.com/r/ProgrammerHumor/comments/6brjkt/how_it_people_see_each_other/ source: https://www.pinterest.com/pin/43769427601903092/ source: https://www.pinterest.com/pin/43769427601903092/

SQL; Unique constraint across tables

Recently I encountered several different data objects that all have a property akin to an 'id assigned by the company'. This field is a human readable string with a prescribed format, incremented by one shared sequence. Using a highly unique property like a UUID was sadly ruled out. In the legacy data there seemed to be clear problems with keeping data consistent even within tables, so the database design is being implemented defensively. It's possible to implement such a field as a One to One relationship from an ' id_from_company ' table to the other tables. But this does not prevent the same id_from_company to be used twice, by using it in two different tables. To uphold uniqueness across multiple tables, each table sadly needed to have a check constraint added, that checks for this uniqueness. I wouldn't soon recommend such a "unique over multiple columns" property, because of the overhead I imagine it creates. But it already existed, and ...

Jargon: postfix

As a guild of craftsmen, we software developers, should be aware of our jargon when talking to others. The jargon can distract from the intention you're trying to convey. One term that I accidentally stumbled upon was 'postfix'. I was creating a method that concatenated  prefix + term + postfix. While writing the code I started wondering if I should have used the term 'suffix' instead of 'postfix'. [JARGON++] Probably I used the term post(fix), because it's a great contrast to pre. Still I was dumbfounded to discover that postfix is a term specifically originating from our field of computer programming (e.g. postfix operators: expr++ and expr-- ). Suffix on the other hand originated in linguistics, a long time ago. So long story short; don't start an argument with that linguist machine learning colleague of yours, you probably both mean the same thing. Sources: https://english.stackexchange.com/questions/81263/postfix-or-suffix https://w...

Confusion of terms

At my present assignment I work with a seasoned senior. One of my current tickets will have some impact on the @Controller layer of the application, so I casually stated that I wanted to redo the DTO's (data transfer objects). In the application that I'm working on DTO's are used to transfer data from clients to the application. After which we got into a discussion, which ended up being more a case of miscommunication than an actual arguments. Question marks were put to my idea of adjusting the DTO's. At that moment he thought I wanted to adjust the objects responsible for representing data in our data source (db). Apparently it's also common practice to call these objects DTO's in some applications, especially if you work with a DAO (Data Access Object) pattern. To confuse the matter even further, I said that I didn't want to adjust the models too much. In the application that I was talking about models (also) represent data to be saved in the database....

Flyway or the highway!

Flyway is a great tool to manage the consistency of your database in Java-land.  For each change in the database schema that is needed to run your application consistently with the db, you place a sql file in the db.migration folder. This allows flyway to manage the migration. Flyway checks if the sql files are already executed (using a hash table in the target database), else it will run the neccessary sql script(s). There is however a little setup required, even within a Spring Boot application. You can use the maven flyway plugin to run flyway migrations with mvn over CLI. This would mean decoupling a major part of your database's consistency management from your application into a build script... Though the only thing a Spring Boot application actually needs, is the flyway-core dependency ( which is recommended by Spring ). Keeping the management within the application. Probably the right choice since in this case the db only exists by the authority of that application....

My problem with Cors POST requests

Just encountered a weird "bug" in the CORS protocol. One of my POST request endpoints accepts a multipart form as content type. In local development the front-end sending the request exists on a different origin. Because of the different origin I expected a blocking response to be send though the cross-origin resource sharing mechanism ( cors ) by the back-end managing the endpoint. The back-end is a Spring boot application. Turns out that the back-end fully processed the form data and send back a 200 Ok response... The only thing good thing that happened is that the front-end didn't display the response because of a missing [ Access-Control-Allow-Origin ] header. After reading a clearer guide on CORS that a POST request with a multipart form as content is not blocked through CORS by design... If it was send with a PUT request a proper blocking response would be generated. In my case the request added entities to the database. Not really desirable with data from u...