Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Spring Data JDBC logs 'Could not safely identify store assignment'

ErrorSpring Data JDBC - Could not safely identify store assignment for repository candidate interface

Short answer

Spring Data found more than one store module on the classpath, for example JPA and JDBC, so it entered strict mode and skipped a repository that carries no JDBC mark. The log line is informational. If the repository should be a JDBC repository, annotate its entity with @Table. If not, you can ignore the line.

  • Applies to Spring Boot 3.4, Spring Data JDBC 3.4, Java 21
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List which Spring Data starters are on the classpath. Two or more store modules is what turns strict mode on.

    ./mvnw dependency:tree | grep -i "spring-data"
    # Gradle: ./gradlew dependencies --configuration runtimeClasspath | grep -i spring-data
  2. 2Match what you see, then jump to its fix

    1. 1A repository bean you expected is missing, and this log line names its interfaceThe entity is meant for JDBC but has no @Table annotationFix
    2. 2The named repository is a JPA repository that works fineThe repository belongs to JPA, and JDBC is only skipping itFix
    3. 3Several repositories extend only Repository or CrudRepository and the store cannot be told apartRepositories of both stores live in the same package and extend generic interfacesFix

What does the error look like?

  • Spring Data JDBC - Could not safely identify store assignment for repository candidate interface
  • If you want this repository to be a JDBC repository, consider annotating your entities with one of these annotations

Cause 1 of 3

The entity is meant for JDBC but has no @Table annotation

1Check

In strict mode Spring Data JDBC only accepts a domain type that carries the @Table annotation from org.springframework.data.relational.core.mapping. Without it, the repository is not registered.

grep -rn "@Table" src/main/java

2Fix

Add the annotation to the entity.

import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;

@Table("customers")
public class Customer {
    @Id Long id;
    String name;
}

3Verify

Start the app: the line is gone for this repository and it is injected.

./mvnw spring-boot:run

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

The repository belongs to JPA, and JDBC is only skipping it

1Check

A repository that extends JpaRepository, or whose entity is annotated with JPA's @Entity, is a valid candidate for JPA only. The JDBC module reports that it skipped it. Nothing is broken.

grep -rn "extends JpaRepository\|@Entity" src/main/java

2Fix

No change is needed. If you do not use JDBC repositories at all, remove the spring-boot-starter-data-jdbc dependency so only one store module remains.

<!-- pom.xml: remove if unused -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>

3Verify

After the dependency is removed, the line no longer appears.

./mvnw spring-boot:run

Confirmed by docs.spring.io

Did this fix it?

Cause 3 of 3

Repositories of both stores live in the same package and extend generic interfaces

1Check

Strict mode binds a repository to a module when it extends a module-specific interface, or when its domain class has the module's annotation. A repository that extends only Repository or CrudRepository, with an entity that has no store annotation, cannot be bound.

grep -rn "extends CrudRepository\|extends Repository" src/main/java

2Fix

Mark each entity for its store, or scope each store to its own packages with base packages.

@EnableJdbcRepositories(basePackages = "com.example.jdbc")
@EnableJpaRepositories(basePackages = "com.example.jpa")
class DataConfig { }

3Verify

Start the app and check that each repository binds to the intended store.

./mvnw spring-boot:run

Confirmed by docs.spring.io

Did this fix it?

How do I stop it coming back?

  • Use one Spring Data store per service where you can, so strict mode never starts.
  • When you mix stores, keep their repositories and entities in separate packages.
  • Do not put JPA and Spring Data annotations of different stores on the same class.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.