一个非常简单的弹簧库:
public interface OrganizationRepository extends CrudRepository<Organization, Long> {
@Query("select o.name from Organization o where o.name like ?1 ")
List<String> findCompanyName(String term);
}
并且调用也简单如下:
@RequestMapping(value="/names", method=RequestMethod.GET)
public @ResponseBody List<String> getCompanyNameList(@RequestParam String term) {
List<String> companyNames=organizationRepository.findCompanyName(term);
return companyNames;
}
但在控制台中,我只得到SQL:
2012-02-17 23:00:18,105 DEBUG: select organizati0_.name as col_0_0_ from Organization organizati0_ where organizati0_.name like ? >>> org.hibernate.engine.jdbc.spi.SqlStatementLogger.logStatement(SqlStatementLogger.java:104)
Hibernate:从organization organizati0_中选择organizati0_.name为col_0_0_,其中organizati0_.name喜欢?
哪里错了?
我正在使用spring-mvc 3.1.0,Spring-data-jpa 1.1.0,hibernate-entitymanger 4.0.1 Final
答案 0 :(得分:1)
查询看起来没问题。
如果您希望查看传递给查询的实际参数值,请将以下条目添加到log4j.properties
log4j.logger.org.hibernate.type=trace
答案 1 :(得分:0)
?是不正确的。它应该是'...其中o.name like:name'。