Hibernate - Parameter value [2011] was not matching type [java.lang.Integer]. How to solve?

泄露秘密 提交于 2020-01-03 06:19:22

问题


I am getting the message above even though the value I'm passing through an Integer to the named query. Can anyone explain why? Thanks

DAO Java Code

Calendar cal = Calendar.getInstance();
cal.setTime(interval.getStartDate());        
query.setParameter("academicYear", new Integer(cal.get(Calendar.YEAR)));

Query:

@NamedQuery(name = "StudentDemographics.findByMOEDEqual", query = "SELECT s.student FROM StudentDemographics s " +
            "WHERE :academicYear = s.academicYear " +
            "AND UPPER(s.MOED) like :MOED"),

Error: Parameter value [2011] was not matching type [java.lang.Integer]

Environment is Spring w Hibernate/JQL + SQL Server


回答1:


I had a similar problem and could fix it this way:

I used long instead of int as a type for the respective field.



来源:https://stackoverflow.com/questions/6622882/hibernate-parameter-value-2011-was-not-matching-type-java-lang-integer-ho

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!