我正在尝试将 Spring-Data-JPA 合并到我的项目中。让我困惑的一件事是如何通过注释实现 setMaxResults(n) ?
例如,我的代码:
public interface UserRepository extends CrudRepository<User , Long>
{
@Query(value="From User u where u.otherObj = ?1 ")
public User findByOtherObj(OtherObj otherObj);
}
我只需one (and only one)
要从 otherObj 返回用户,但我找不到注释 maxResults 的方法。有人可以给我一个提示吗?
(mysql抱怨:
com.mysql.jdbc.JDBC4PreparedStatement@5add5415: select user0_.id as id100_, user0_.created as created100_ from User user0_ where user0_.id=2 limit ** NOT SPECIFIED **
WARN util.JDBCExceptionReporter - SQL Error: 0, SQLState: 07001
ERROR util.JDBCExceptionReporter - No value specified for parameter 2
)
我找到了一个链接:https ://jira.springsource.org/browse/DATAJPA-147 ,我试过但失败了。现在好像不行了?为什么 Spring-Data 没有内置如此重要的功能?
如果我手动实现此功能:
public class UserRepositoryImpl implements UserRepository
我必须在 中实现大量预定义的方法CrudRepository
,这太糟糕了。
环境:spring-3.1、spring-data-jpa-1.0.3.RELEASE.jar、spring-data-commons-core-1.1.0.RELEASE.jar