我正在尝试将Spring-Data-JPA合并到我的项目中。让我困惑的一件事是如何通过注释实现setMaxResults(n)?
例如,我的代码:
public interface UserRepository extends CrudRepository
{
@Query(value="From User u where u.otherObj = ?1 ")
public User findByOhterObj(OtherObj otherObj);
}
我只需要从otherObj返回CrudRepository用户,但我找不到一种方法来注释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