In today’s article, we will take a look at composite primary key support in two top Java ORMs: jOOQ and Hibernate. We’ll look at a couple examples, learn how column configuration looks in Hibernate, and how support is organized in jOOQ. The composite primary key is a key that consists of more than one column, and its column combination guarantees its uniqueness. To handle the connection to the database, the application uses libraries known as object-relational mappers, or ORMs.
I’ve been testing a ton of frameworks lately – good and otherwise. One of them, the Java micro framework Spark, really amazed me with its simplicity and rapid development capabilities. In this article, we’ll examine an example of Spark’s usefulness by creating a REST API. So, without further ado, let’s see how to store, retrieve, update and delete some information in a PostgreSQL database using jOOQ ORM over a RESTful API in a simple To-do app.
Why SQL Is Neither Legacy, nor Low-Level, nor Difficult, nor the Wrong Place for (Business) Data Logic, but Is Simply Awesome!
The following fallacies are things that I hear all the time. SQL is legacy. Why can’t we work with more modern tech? – Timeless. E.g. by someone who thinks that NoSQL databases are “modern”. SQL is low level, like assembler. Would you prefer to work with assembler or with Java? Similarly, would you prefer to work with SQL or with Hibernate? – Timeless. Someone who thinks that SQL is low-level.
jOOQ is a Java Object-Relational Mapper that lets you build type safe SQL queries through its fluent API. Using built-in Vertabelo support we can generate sufficient code from the previously designed model. Generated Java classes correspond to database tables, records, etc. This time, we automate this process by using Gradle build system. There are two ways to generate ready to use Java classes with Vertabelo: Generate jOOQ classes via Vertabelo XML Generate jOOQ classes via Vertabelo API Generate jOOQ Classes via Vertabelo XML Design your database model online in Vertabelo.
jOOQ provides an easy way to automate the process of generating the java classes that represent database tables, records, etc. via the jooq-codegen-maven plugin. This time we let Maven worry about downloading the required JAR files and generating Java code that lets you build typesafe SQL queries through jOOQ’s fluent API. There are two ways to generate ready to use Java classes with Maven and Vertabelo: Generate jOOQ classes via Vertabelo XML Generate jOOQ classes via Vertabelo API Generate jOOQ Classes via Vertabelo XML Design your database model online in Vertabelo.
It often happens that if something is loved, it is also hated with the same power. The idea of object relational mapping fits into this concept perfectly. You will definitely come across many opposite points and fierce discussions as well as unwavering advocates and haters. So if you have ever asked whether to use ORM or not, the answer “it depends” will not be enough. What Is an Object-Relational Mapping (ORM)?
jOOQ and Vertabelo perfectly complement each other in the application development lifecycle. With Vertabelo you can easily design a database structure that saves you from writing DDL code manually, while jOOQ handles the generation of Java classes corresponding to database tables, and allows to construct SQL queries through its fluent API. The integration of Vertabelo and jOOQ has been the subject of several articles published on our blog. Unfortunately, all of them, including “The easiest ERD + ORM integration ever: Vertabelo and jOOQ”, are intended for users having some previous experience with jOOQ.
What is jOOQ? jOOQ, which stands for "jOOQ Object Oriented Querying," is an ORM (object-relational mapping) for Java. With jOOQ you don't write statements with "SQL-like language"; like Hibernate's HQL. Instead, you write well designed and intuitive DSL code which, for someone speaking SQL, is obvious and self-explanatory. Read more » Some time ago I announced that the integration of Vertabelo and jOOQ was coming soon. While we're waiting for an official (stable) jOOQ release to support this integration, I'd like to present you with some of the details about how to use this new feature.
In the Java world, there are many standards. Some of them have grown up from commonly used libraries or frameworks. For example, JPA, which was highly influenced by Hibernate. Standards are good. They eliminate chaos and bad practices. But standards shouldn’t be a kind of Bible for developers. A set of tools used in the project should be chosen consciously, not blindly “because it’s a standard and others use it.