close

Jens Schauder

Jens Schauder

Spring Data team member

Brunswick, Germany

Blog Posts by Jens Schauder

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...

Spring Data Lovelace SR6, Kay SR14, Ingalls SR20 Released

On behalf of the entire team I’d like to announce the availability of three service releases for Spring Data release trains: Lovelace SR6, Kay SR14, and Ingalls SR20.

The releases are recommended upgrades as they contain fixes for a CVE in Spring Data JPA.

Spring Boot 2.1.4, 2.0.9, and 1.5.20 already pull in the above Spring Data versions, including the fixes that were released last week, and are now also available for use.

Here’s the content of the releases:

Spring Data Lovelace SR6

Read more...

Spring Data JDBC, References, and Aggregates

In my previous blog article, I described how to set up and use Spring Data JDBC. I also described the premise of making Spring Data JDBC easier to understand than JPA. This becomes interesting once you consider references. As a first example, consider the following domain model:

class PurchaseOrder {

  private @Id Long id;
  private String shippingAddress;
  private Set<OrderItem> items = new HashSet<>();

  void addItem(int quantity, String product) {
    items.add(createOrderItem(quantity, product));
  }

  private OrderItem createOrderItem(int quantity, String product) {

    OrderItem item = new OrderItem();
    item.product = product;
    item.quantity = quantity;
    return item;
  }
}
Read more...

Introducing Spring Data JDBC

With the upcoming Lovelace GA release, we’re going to ship a new Spring Data Module: Spring Data JDBC.

The idea behind Spring Data JDBC is to provide access to relational databases without submitting to the complexities of JPA. JPA offers such features as lazy loading, caching, and dirty tracking. While these are great if you need them, they can actually make thinking about JPA and its behavior harder than it has to be.

Lazy loading might trigger expensive statements when you don’t expect it or it might fail with an exception. Caching can get in your way when you actually want to compare two versions of an entity and being dirty makes it hard to find a single point where all persistence operations pass through.

Read more...