如何编写Spring Data方法名来检索列中的所有元素?

m3t*_*man 3 java orm spring jpa spring-data

假设我有班级:

@Entity
public class Bean {
    @Id
    private String beanId;
    //other fields & setters and getters
}
Run Code Online (Sandbox Code Playgroud)

以及相应的Spring Data JPA存储库,我希望在List<String>所有存储库中存在beanIds.

@RepositoryDefinition(domainClass = Bean.class, idClass = String.class)
public interface BeanRepository {
    @Query("select b.beanId from Bean b")
    List<String> findAllBeanId();
}
Run Code Online (Sandbox Code Playgroud)

如上所述,一切都按预期工作; 但这是一个简单的操作,我不想显式编写查询.该方法的名称应该是什么,以便Spring Data可以解析它并获得上述查询(或相同的功能).我在参考文档中搜索了两本关于Spring Data的书.上述域名(findAllBeanId)和其他人,我已经试过(findBeanId,findBeanBeanId等)抛出以下异常的根本原因:

org.springframework.data.mapping.PropertyReferenceException: No property find found for type Trade
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:353)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:271)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:245)
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:72)
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:180)
    at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:260)
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:240)
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:68)
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:57)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:90)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:162)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:68)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:279)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:147)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:153)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:43)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
    ... 22 more
Run Code Online (Sandbox Code Playgroud)

rag*_*nor 5

在Spring文档中:http://static.springsource.org/spring-data/jpa/docs/1.3.0.RELEASE/reference/html/jpa.repositories.html没有任何关于从实体中获取特定列/属性的信息通过从方法名称生成的查询.所以我认为目前这是不可能的.