xautlx / s2jh

A Java/J2EE development framework for enterprise system based on Struts/Spring/JPA/Hibernate and jquery/bootstrap
GNU Lesser General Public License v3.0
321 stars 242 forks source link

spring-data-jpa语句的问题 #21

Closed smilesman closed 11 years ago

smilesman commented 11 years ago

@Query("select count(*) from Holidays h where h.year=:year and h.month=:month and h.day >= 1 and h.day<=:day") public int getCountHoliday(@Param("year")int year,@Param("month")int month,@Param("day")int day);

会抛出参数不匹配的错误 Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1

xautlx commented 11 years ago

经过实际验证,未重现此问题。 具体验证代码参考:XxBjDao @Query("select count(*) from XxBj t where t.bh = :bh") Long findXsCount(@Param("bh") String bh);

public class XxBjDaoTest extends SpringTransactionalTestCase {

@Autowired
private XxBjDao xxBjDao;

@Test
public void findXsCount() {
    XxBj xxBj = TestObjectUtils.buildMockObject(XxBj.class);
    xxBjDao.save(xxBj);
    Long count = xxBjDao.findXsCount(xxBj.getBh());
    Assert.assertTrue(count >= 1);
}

}

执行结果:

21:38:43.426 DEBUG jdbc.sqlonly[232] - sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)

  1. insert into biz_xx_bj (bh, bjmc, bzrgh, nj, sfssmzsyjxb, ssnj, syjxmsm, syjxssmzyym, ssxx, xz, zym, id) values ('qATTEegJek', 'XwCnzhVsrrPaHqxWiysi', 'TjGokXYzOyZBGOfbBAYi', 'werYjvTEeV', '1', 'tVbObuZKPv', 'b', 'kvl', 'qYREqiNyFi', 0.774146912333156134167211348540149629116058349609375, 'LrOcbv', '402880c5415fa47d01415fa4940a0000')
    21:38:43.434 DEBUG jdbc.sqlonly[232] - sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
  2. select count(*) as col_00 from biz_xxbj xxbj0 where xxbj0_.bh='qATTEegJek' limit 2