Spring Data is one programming model for many stores. Use the lighter Spring Data JDBC for simple SQL, and Spring Data MongoDB for documents — with the same repository style.
Note: Spring Data JPA (Hibernate) is full-featured with lazy loading and a persistence context. Spring Data JDBC is simpler and more predictable — no lazy loading, no caching, plain SQL mapping. Spring Data MongoDB stores documents instead of rows. All three share the same Repository abstraction you already know.
Why: a lighter alternative to JPA when you want straightforward object-to-table mapping without Hibernate’s machinery. Note: add spring-boot-starter-data-jdbc, annotate the id with @Id, and extend CrudRepository — derived queries and @Query work, but there is no lazy loading.
import org.springframework.data.annotation.Id;
public record Book(@Id Long id, String title, String author, double price) {}import org.springframework.data.repository.CrudRepository;
public interface BookRepository extends CrudRepository<Book, Long> {
List<Book> findByAuthor(String author); // derived queries still work
}When MongoDB: flexible, schema-light document data. Note: add spring-boot-starter-data-mongodb, map the class with @Document, the key with @Id, and extend MongoRepository. The repository style is identical — only the annotations and the store differ.
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document("books")
public class Book {
@Id private String id; // Mongo ids are strings
private String title;
private List<String> tags; // documents nest naturally
}import org.springframework.data.mongodb.repository.MongoRepository;
public interface BookRepository extends MongoRepository<Book, String> {
List<Book> findByTagsContaining(String tag);
}# application.properties
spring.data.mongodb.uri=mongodb://localhost:27017/bookstore