[hibernate-issues] [Hibernate-JIRA] Created: (HHH-7080) Sql translation problem with spring repository
deng hui (JIRA)
noreply at atlassian.com
Sat Feb 18 01:24:12 EST 2012
Sql translation problem with spring repository
-----------------------------------------------
Key: HHH-7080
URL: https://hibernate.onjira.com/browse/HHH-7080
Project: Hibernate ORM
Issue Type: Bug
Environment: spring-mvc-3.1.0.RELEASE, spring-data-jpa-1.1.0.SNAPSHOT
hibernate-entitymanager-4.0.1.FINAL
Reporter: deng hui
if we define a spring repository like:
{code}
public interface OrganizationRepository extends CrudRepository<Organization, Long> {
@Query("select o from Organization o where o.name like '?1'")
List<Organization> findByNameLike(String pattern);
@Query("select o.name from Organization o where o.name like ?1 ")
List<String> findCompanyName(String name);
}
{code}
then we call it in a controller:
{code}
@Controller
@RequestMapping("/organization")
public class OrganizationController {
@Autowired
private OrganizationRepository organizationRepository;
@RequestMapping(value="/names", method=RequestMethod.GET)
public @ResponseBody List<String> getCompanyNameList(@RequestParam String term) {
List<String> companyNames=organizationRepository.findCompanyName(term);
return companyNames;
}
}
{code}
the controller always failed at query parameter translation and we got a debug info as:
{code}
2012-02-18 13:20:19,739 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: select organizati0_.name as col_0_0_ from Organization organizati0_ where organizati0_.name like ?
{code}
after trace the setup of application I find these 2 queries in repository have already been compiled in advance by class QueryTranslatorImpl as:
{code}
select organizati0_.id as id7_, organizati0_.createTime as createTime7_, organizati0_.creator_id as creator6_7_, organizati0_.privileges as privileges7_, organizati0_.state_id as state7_7_, organizati0_.updateTime as updateTime7_, organizati0_.updator_id as updator8_7_, organizati0_.manager_id as manager9_7_, organizati0_.name as name7_ from Organization organizati0_ where organizati0_.name like '?1'
{code}
and
{code}
select organizati0_.name as col_0_0_ from Organization organizati0_ where organizati0_.name like ?
{code}
wondering why one *?* and another *?1*, will these debug info show the final sql after parameter translation?
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list