Spring Data JPA :创建抽象存储库
2022-09-04 02:29:23
给定以下类:
@MappedSuperclass
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
@DiscriminatorColumn(name="animalType",discriminatorType=DiscriminatorType.STRING)
@QueryExclude
public abstract class Animal {}
@Entity
@DiscriminatorValue("dog")
public class Dog {}
@Entity
@DiscriminatorValue("cat")
public class Cat {}
是否可以以某种方式为 配置 JPA 存储库?Animal
我试过了
public interface AnimalRepository extends JpaRepository<Animal,Long>
但是,这失败了,
java.lang.IllegalArgumentException: Not a managed type: Animal
有没有办法配置它?
我希望能够执行以下任务:
@Autowired
private AnimalRepository repository;
public void doSomething()
{
Animal animal = repository.findById(123);
animal.speak();
}