I've got this class DepartmentPerson in Java where I've mapped a Map in Hibernate as following:
<map cascade="save-update" name="acceptByPeriod" table="tbl_department_people_accept">
<key column="fk_department_people_asc_id"/>
<map-key column="fk_period_id" type="int"/>
<element type="int" column="fld_accept"/>
</map>
and in the class I have acceptByPeriod defined as following:
private Map<Integer, Integer> acceptByPeriod = new HashMap<>();
Whenever I run a query on DepartmentPerson, I get the message: "java.lang.IllegalArgumentException: argument type mismatch". This has something to do with the acceptByPeriod mapping, as when I remove it the problem disappears. All 3 fields on array tbl_department_people_accept are of type int. I really can't understand what is going wrong; I've done this type of mapping before in different classes (with a <Integer, Date> map and an <Integer,DepartmentEEK> map, DepartmentEEK being a composite-element) and it worked just fine; in fact I've copied the code from one of those classes and just changed the names of the fields. I am at my wits' end here. Any idea how to get it to work, or at least how to get to the bottom of which field is giving an argument type mismatch?
CodePudding user response:
Found the problem with the help of this post: IllegalArgumentException: argument type mismatch in Hibernate
The problem wasn't in the types of the map, it was in its setter. I had written it as:
public void setAcceptByPeriod(HashMap<Integer, Integer> acceptByPeriod)
when it needed to be
public void setAcceptByPeriod(Map<Integer, Integer> acceptByPeriod)