JPA 查询参数在 Hibernate 中的位置?
Posted
技术标签:
【中文标题】JPA 查询参数在 Hibernate 中的位置?【英文标题】:Where the JPA query parameter is shipped in Hibernate? 【发布时间】:2012-02-17 15:05:02 【问题描述】:一个非常简单的spring仓库:
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)
休眠:从组织organizati0_中选择organizati0_.name as col_0_0_ whereorganizati0_.name like ?
哪里出错了?
我正在使用 spring-mvc 3.1.0、Spring-data-jpa 1.1.0、hibernate-entitymanger 4.0.1 Final
【问题讨论】:
【参考方案1】:查询看起来没问题。
如果您希望查看传递给查询的实际参数值,请将以下条目添加到 log4j.properties
log4j.logger.org.hibernate.type=trace
【讨论】:
【参考方案2】:那个?是不正确的。它应该类似于 '...where o.name like :name'。
【讨论】:
以上是关于JPA 查询参数在 Hibernate 中的位置?的主要内容,如果未能解决你的问题,请参考以下文章
org.hibernate.QueryException:JPA 风格的位置参数不是一个完整的序数
如何更新 Spring Data JPA @Modifying @Query 查询中的 JPA/Hibernate @Version 字段?