我知道如何使用CrudRepository
与某个实体相关...
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
public interface MyEntityRepository extends CrudRepository<MyEntity, Long>, JpaRepository<MyEntity, Long> {
//MyCustom Queries
}
但是,我需要使用与特定实体无关的查询(不存在特定实体,并且我具有这些类型的多个查询) 我只想将所有这些查询放在一个类中。
这里的代码类似于...
import java.util.List;
import org.springframework.data.jpa.repository.Query;
public class MyGeneralRepository {
static final String QUERY_findCompoundResult
= "SELECT ta.param1, tb.param2 "
+ "FROM myscheme.tablea ta, myscheme.tableb tb "
+ "WHERE ta.param2 = tb.param2 ";
@Query(value = QUERY_findCompoundResult, nativeQuery = true)
List<Object[]> findCompoundResult();
}
现在在我的IDE中,我有:missing method body, or declare abstract
,显然是因为我没有实现方法。
然后我的问题:
如何在不关联任何实体的情况下挖掘CrudRepository的潜力?
有可能吗?