Issue
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> {
}
Solution
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> {
}
Answered By - Manjunath H M
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)