Java 自定义通用spring数据存储库
使用spring数据,我有两个共享相同结构的表。 这两个表由两个不同的实体表示,它们继承自同一个类:Java 自定义通用spring数据存储库,java,spring,spring-data-jpa,spring-data,Java,Spring,Spring Data Jpa,Spring Data,使用spring数据,我有两个共享相同结构的表。 这两个表由两个不同的实体表示,它们继承自同一个类: @MappedSuperclass public abstract class SuperEntity<T extends SuperEntity> { // ... } @Table(name = "FOO") @Entity public class Foo extends SuperEntity<Foo> { // ... } @Table(name = "BA
@MappedSuperclass
public abstract class SuperEntity<T extends SuperEntity> {
// ...
}
@Table(name = "FOO")
@Entity
public class Foo extends SuperEntity<Foo> {
// ...
}
@Table(name = "BAR")
@Entity
public class Bar extends SuperEntity<Bar> {
// ...
}
不确定我做错了什么,但Spring似乎认为myCustomRequest是来自实体的属性,而不是方法
我使用的是SpringBoot1.5.6和SpringDataJPA1.11.6
幸运的是,我能够复制您的问题 spring如何推荐自定义存储库实现是在spring文档中指定的 所以,你可以做如下的事情
public interface CustomEntityRepository<T extends SuperTag<?>>
public interface FooRepository extends JpaRepository<Foo, Integer>, CustomEntityRepository<Foo>
public interface BarRepository extends JpaRepository<Bar, Integer>, CustomEntityRepository<Bar>
公共界面CustomEntityRepository>
如下所示
@Repository
// NOTE: Implementation name must follow convension as InterfaceName + 'Impl'
public class CustomEntityRepositoryImpl<T extends SuperTag<?>> implements
CustomEntityRepository<T> {
@PersistenceContext
private EntityManager entityManager;
// Generic custom implementation here
}
@存储库
//注意:实现名称必须遵循约定,如InterfaceName+“Impl”
public class customentityrepositoryimplic感谢您的帮助,但是在修改我的代码以适合您的代码之后并不能解决我的问题。你会有一个工作的例子吗?你可以参考这个名字是相当不同的,希望这有帮助。感谢你的努力,但是我认为我的问题是我没有使用相同版本的spring data jpa。这里有一个小例子:正如我所注意到的,这个问题只有在回购是通用的情况下才会发生。。你解决这个问题了吗?
org.springframework.data.mapping.PropertyReferenceException: No property myCustomRequest found for type Foo!
public interface CustomEntityRepository<T extends SuperTag<?>>
public interface FooRepository extends JpaRepository<Foo, Integer>, CustomEntityRepository<Foo>
public interface BarRepository extends JpaRepository<Bar, Integer>, CustomEntityRepository<Bar>
@Repository
// NOTE: Implementation name must follow convension as InterfaceName + 'Impl'
public class CustomEntityRepositoryImpl<T extends SuperTag<?>> implements
CustomEntityRepository<T> {
@PersistenceContext
private EntityManager entityManager;
// Generic custom implementation here
}