Home > Software engineering >  Spring Boot JPA - JPA Repository does not list the findByXXX columns
Spring Boot JPA - JPA Repository does not list the findByXXX columns

Time:10-06

I create a spring-boot application with the follow maven dependencies:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hyperledger.fabric</groupId>
            <artifactId>fabric-gateway-java</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-mysql</artifactId>
        </dependency>
    </dependencies>

I created an entity Control like follows:

import lombok.Data;

import javax.persistence.*;

@Entity
@Data
public class Control {

    @Id
    private String id;
    private String channel;
    private String chaincode;

}

And a repository for control:

enter image description here

You can see that it does not appear my Control columns in the findByXXX options..

I do not know why..

Any help is appreciated.

CodePudding user response:

try declaring the return type of method like

void findByXXX

or

Control findByXXX

CodePudding user response:

the error i made regarding the exists was that when i created a custom method i was forgetting the final s on exists.

This is i was defining in my repo:

boolean existByChannel(String channel);

When it should be:

boolean existsByChannel(String channel);

What a rooky mistake. Sorry

  • Related