close

Jens Schauder

Jens Schauder

Spring Data team member

Brunswick, Germany

Blog Posts by Jens Schauder

Spring Data JDBC - How to use custom ID generation

This is the first article of a series about how to tackle various challenges you might encounter when using Spring Data JDBC.

If you are new to Spring Data JDBC, you should start by reading its introduction and this article, which explains the relevance of aggregates in the context of Spring Data JDBC. Trust me, it is important.

This article is based on part of a talk I did at Spring One 2021.

Now we can get started with IDs - especially about what your options are when you want to control the ID of an entity and do not want to leave it to the database. But let us first reiterate Spring Data JDBC’s default strategy for this.

Read more...

Spring Data 2021.1.0-M2 released

On behalf of the team, I’m pleased to announce the availability of the Spring Data 2021.1.0-M2 milestone release.

The release is built on top of Spring Framework 5.3.9.
For your convenience, you can consume this release through Spring Boot 2.6.0-M2, which our team mates on the Boot team will release in about a week.

To round things off, here are the links to the artifacts, changelogs, and documentation:

Read more...

Spring Data 2021.0.4 and 2020.0.12 released

On behalf of the team, I’m pleased to announce the availability of the Spring Data2021.0.4 and 2020.0.12 service releases.

Both releases are built on top of Spring Framework 5.3.9. For your convenience, you can consume these releases through Spring Boot 2.5.4 and 2.4.10, respectively. Our teammates on the Boot team will release those in about a week.

The service releases ship with mostly bug fixes and dependency upgrades.

To round things off, here are the links to the artifacts, changelogs, and documentation:

Read more...

Spring Data 2021.0.3 and 2020.0.11 released

On behalf of the team, I’m pleased to announce the availability of the Spring Data2021.0.2 and 2020.0.10 service releases.

Both releases are built on top of Spring Framework 5.3.9. For your convenience, you can consume these releases through Spring Boot 2.5.3 and 2.4.9, respectively. Our teammates on the Boot team will release those in about a week.

The service releases ship with mostly bug fixes and dependency upgrades.

To round things off, here are the links to the artifacts, changelogs, and documentation:

Read more...

Spring Data 2021.1.0-M1 released

On behalf of the team, I’m pleased to announce the availability of the Spring Data 2021.1.0-M1 milestone release.

The release is built on top of Spring Framework 5.3.9. For your convenience, you can consume this release through Spring Boot 2.6.0-M1, which our team mates on the Boot team will release in about a week.

The 2021.1 release train ships a set of features and dependency upgrades.
The most important changes are:

  • Upgrade to Querydsl 5.
  • Support for a wide range of Redis 6.2 commands.
  • Support for dialect-dependent custom conversions in Spring Data JDBC. This was used to improve the support of java.time types across multiple databases.
  • Support for streaming large result sets in Spring Data JDBC.
  • Support for AggregateReference in query derivation.
  • REF_CURSOR support for stored procedures in Spring Data JPA.
  • Upgrade to MongoDB Driver 4.3 and initial support for MongoDB Server 5.0 Time Series.
  • Spring Data MongoDB comes with extended capabilities for linking documents and offers, next to the existing DBRef approach, a property-based solution that uses simple values, such as the target _id or a combination of fields to link to another document.
    The sample below shows the reference to a collection of Account documents through their _id in Java code and how it is represented in MongoDB:

    @Document
    class Person {
      @Id
      String id;
      @DocumentReference
      List<Account> accounts;
    }
    
    {
      "_id" : …,
      "accounts" : [ "6509b9e" … ]
    }
    
Read more...

Spring Data 2020.0 - New and Noteworthy in Spring Data JDBC 2.1

As part of the 2020.0.0 version of Spring Data, we released Spring Data JDBC 2.1. This article presents the four most interesting changes in this version.

Use @Value on Entity Constructor Arguments

In some cases, not all the data that goes into an entity comes from the ResultSet of a query. You now may provide an @Value annotation with a SPeL expression that is evaluated, and the result is passed as an argument upon construction of the entity.

Read more...

Migrating to Spring Data JDBC 2.0

With Spring Data JDBC 2.0, we had to introduce some breaking changes. The goal of this article is to help in the migration process.

TL;DR

  1. Use the default letter casing for custom column and table names or quote the names for table generation exactly as used in the annotations.

  2. Use AbstractJdbcConfiguration for custom configuration of the application context.

  3. Register a Dialect if necessary.

  4. Review event-handling code and ensure the data you try to use is not null.

Quoting of Identifiers

Spring Data JDBC 1.x uses table and column names mostly without changing them. This causes problems when you use an SQL key word as a property or entity name or when you tried to use some special character in a column name.

For this reason Spring Data JDBC 2.0 quotes all identifiers by default. This makes the names case-sensitive, at least for most databases. Since we also, by default, convert the names generated into the default letter casing used by the database, this should not cause any problems, assuming you used no quotes in the CREATE TABLE statements, as most people do.

For example, consider a Student entity, as follows:

class Student {

    @Id
    Long id;
    String name;
}

A matching table for H2 could look like this:

CREATE TABLE STUDENT
(
    ID SERIAL PRIMARY KEY,
    NAME  VARCHAR(30)
);

That example is the same as in previous versions of Spring Data JDBC. Things change when you specify column or table names explicitly with @Column, @Table, or @MappedCollection. In this case, we assume that you specify the name exactly as you want it to be used and, therefore, the table definition has to use quoted identifiers or the names have to use the default letter casing of your database, as in this modified student example:

@Table("student")
class Student {

    @Id
    Long id;
    @Column("LAST_NAME")
    String name;
}

A matching table for H2 could look like this:

CREATE TABLE "student" -- (1)
(
    ID SERIAL PRIMARY KEY,
    LAST_NAME  VARCHAR(30) -- (2)
);
  1. The table name must be quoted, because it is given in lower-case letters but H2 converts unquoted SQL identifiers to upper case by default.

  2. LAST_NAME does not have to get quoted because it already uses the default letter casing.

See below how to disable the forced quoting if you really want to.

Read more...

Spring Data Neumann M4 released

On behalf of the community, I’d like to announce the availability of the Spring Data Neumann M4 milestone release. It is planned to be the last milestone before the first release candidate.

Neumann M4 ships with 69 tickets fixed. It is built on top of Spring Framework 5.2.4 and will be picked up by Spring Boot 2.3.0 M3 for your convenience.

Finally, here are links to the reference documentation, changelogs, and artifacts of the individual project releases:

Read more...

Spring Data Moore SR3 and Lovelace SR14 released

On behalf of the community, we are pleased to announce that Spring Data Moore SR3 and Lovelace SR14 are now available from Maven Central. Both releases ship with almost 70 tickets in total, mostly bugfixes and dependency upgrades.

Moore SR3 is built on top of the recently released Spring Framework 5.2.2 and will be picked up by Spring Boot 2.2.2 for easier consumption and Lovelace SR14 is built on top of the recently released Spring Framework 5.1.12 and will be picked up by Spring Boot 2.1.11 for easier consumption.

Read more...

Spring Data Moore SR1 and Lovelace SR12 released

On behalf of the team, I’m pleased to announce Spring Data releases Moore SR1, and Lovelace SR12. All releases pick up the most recent Spring Framework releases and will be picked up by Spring Boot 2.2.1, and 2.1.10 respectively.

Moore SR1

Read more...