【发布时间】:2012-03-08 00:23:26
【问题描述】:
我正在尝试将 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);
}
我只需要从 otherObj 返回one (and only one) User,但我找不到注释 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
【问题讨论】:
标签: java spring jpa spring-data spring-data-jpa