Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repository not extending JpaRepository

I'm new to using JPA, I am reading tutorials online and all of them extend from JPARespository like below

from this page

https://www.callicoder.com/spring-boot-jpa-hibernate-postgresql-restful-crud-api-example/

package com.example.postgresdemo.repository;

import com.example.postgresdemo.model.Answer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface AnswerRepository extends JpaRepository<Answer, Long> {
    List<Answer> findByQuestionId(Long questionId);
}

But in my project Eclipse complains with the following

The type JpaRepository<Property,Long> cannot be the superclass of PropertyRepository; a superclass must be a class

Below is my class

package realestate.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import realestate.model.Property;

import java.util.List;

@Repository
public class PropertyRepository extends JpaRepository<Property, Long> {


}
like image 584
Arya Avatar asked Dec 21 '25 21:12

Arya


1 Answers

Basically JPA Repositories are interfaces.

In your code you declared a class and extending it with an interface. A Class can implement an interface, but not extends it.

So please change Class declaration to an interface as below.

@Repository
public class PropertyRepository extends JpaRepository<Property, Long> {    

}

to

@Repository
public interface PropertyRepository extends JpaRepository<Property, Long> {
    
}
like image 164
Manjunath H M Avatar answered Dec 24 '25 10:12

Manjunath H M