Announcement Announcement Module
Collapse
No announcement yet.
parameter translation failed when using Spring @Query to define sql statement Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • parameter translation failed when using Spring @Query to define sql statement

    when I define a repository as:
    Code:
    public interface OrganizationRepository extends CrudRepository<Organization, Long> {
    
    	@Query("select o.name from Organization o where o.name like :pattern ")
    	List<String> findCompanyName(@Param("pattern") String name);
    }
    and invoke in 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) throws Exception{
    		List<String> companyNames=organizationRepository.findCompanyName(term);
    		
    		return companyNames;
    	}
    
    }
    at runtime, I get the a debug info like:
    Code:
    2012-02-18 16:35:40,763 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 ?
    and can't get the expected result?
    I suppose the sql should be something like:
    Code:
    select organizati0_.name as col_0_0_ from Organization organizati0_ where organizati0_.name like 'abc'
    where is the problem?
Working...
X