The Spring Data Repository


The Spring Data repository abstraction simplifies dealing with data models by reducing the amount of boilerplate code required to implement data access layers for various persistence stores (such as JPA). @Repository and its sub-interfaces like @CrudRepository are the central concept in Spring Data which are marker interfaces to provide data manipulation functionality for the entity class that is being managed. When the application starts, Quarkus configures the required persistence technologies and provides an implementation for the interfaces used.

Creating the Model

The first step is to create the data model. Create a new file at:  


The object will be a simple POJO representing details about a type of fruit. Enter the following into

package org.acme.quickstart;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

public class Fruit {

    private Long id;

    private String name;

    private String color;

    public Fruit() {

    public Fruit(String name, String color) { = name;
        this.color = color;

    public Long getId() {
        return id;

    public void setId(Long id) { = id;

    public String getName() {
        return name;

    public void setName(String name) { = name;

    public String getColor() {
        return color;

    public void setColor(String color) {
        this.color = color;

Creating the Spring Data Repository

The next step is to create the data repository. Create a new file at the following location:

Edit the file, adding in the following contents:

package org.acme.quickstart;


import java.util.List;

public interface FruitRepository extends CrudRepository<Fruit, Long> {

    List<Fruit> findByColor(String color);


The key feature here is the CrudRepository base class, which provides a complete set of methods to manipulate the entity (count(), findAll(), delete(), and others).

Creating Sample Data

Finally, we need some sample data to work with. Create and open a new file to hold the sample data at:  


Enter the following SQL commands into that file:

INSERT INTO fruit(id, name, color) VALUES (nextval('hibernate_sequence'), 'cherry', 'red');
INSERT INTO fruit(id, name, color) VALUES (nextval('hibernate_sequence'), 'orange', 'orange');
INSERT INTO fruit(id, name, color) VALUES (nextval('hibernate_sequence'), 'banana', 'yellow');
INSERT INTO fruit(id, name, color) VALUES (nextval('hibernate_sequence'), 'avocado', 'green');
INSERT INTO fruit(id, name, color) VALUES (nextval('hibernate_sequence'), 'strawberry', 'red');
Note: Although you are using `import.sql` to initialize the database in your application, you shouldn't use this in production. Instead, review suggested uses of Hibernate ORM in production.

Configuring Quarkus

The last step is to configure the application with database connection settings. Edit the file:  

And enter the following values:

Next Steps

Now that the data model has been created and you have some sample data, you'll need to create the necessary beans to provide access to that data.