简体   繁体   中英

Spring JPA: PropertyReferenceException: No property findAll found for type

I've searched for hours on this issue but cannot find one that matches my situation exactly and has a solution.

I have an existing Cassandra database but intend to migrate to MongoDB in the near future. I'm writing a Spring Rest API with Spring Data JPA to use the Cassandra DB but want to make sure that I can easily switch to Mongo without much pain in the future.

@Entity
@Table("stb") 
public class NetworkDevice {
    @Id
    @PrimaryKeyColumn(name = "deviceid", type = PrimaryKeyType.PARTITIONED)
    private String deviceid;
// remaining fields/getters/setters/etc omitted

The common NetworkDeviceRepository

public interface NetworkDeviceRepository {
    NetworkDevice findByDeviceid(String deviceid);
}

The Cassandra Repository

public interface NetworkDeviceCassandraRepository extends NetworkDeviceRepository, CassandraRepository<NetworkDevice, String>{}

The Mongo Repository

public interface NetworkDeviceMongoRepository extends NetworkDeviceRepository, MongoRepository<NetworkDevice, String> {}

When the project starts I end up with the following error

Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type NetworkDevice!

It appears as though Spring is getting confused and looking for CrudRepository method names as fields on my NetworkDevice object, but that makes absolutely no sense to me and nothing I've tried (for hours) affects the issue.

Any help would be greatly appreciated, thanks

I found the issue. Apparently Cassandra was identifying the NetworkDeviceMongoRepository as a potential Cassandra repository because it was in the same package as the NetworkDeviceCassandraRepository .

Moving these two Repositories to different packages resolved the issue.

Before


> Repository Package
    + NetworkDeviceRepository.java
    + NetworkDeviceMongoRepository.java
    + NetworkDeviceCassandraRepository.java

After


> Repository Package
    + NetworkDeviceRepository.java
    > Mongo Package
        + NetworkDeviceMongoRepository.java
    > Cassandra Package
        + NetworkDeviceCassandraRepository.java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM