This discussion is archived
2 Replies Latest reply: Sep 28, 2010 1:40 AM by jduprez RSS

IllegalArgumentException occured while calling setter of

800624 Newbie
Currently Being Moderated
Hi all!
I'm new to hiberbate and i'm trying to create my first project. When I'm trying to select data from my DB - I get the fillowing error:
IllegalArgumentException occured while calling setter of test4.Group.groupid
Hibernate: select this_.groupid as groupid1_0_, this_.faculty as faculty1_0_ from studgroups this_
DB has the following entities:
• Student
◦ First Name
◦ Last Name
◦ Patronymic
◦ Datre of Birth
◦ GroupNumber
• Group
◦ GroupNumber
◦ Faculty
I create the following classes:


public class Student {
private Long id;
private String firstname;
private String lastname;
private String otch;
private Date dateofbirth;
private Long groupid;
public Student(){}
public void setId(Long id) {
this.id = id;
}
public void setFirstname(String firstname) {
this.firstname = firstname;

}
public void setLastname(String lastName) {
this.lastname = lastname;
}
public void setOtch(String otch) {
this.otch = otch;
}
public void setDateofbirth(Date dateofbirth) {
this.dateofbirth = dateofbirth;
}
public Long getId() {
return id;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
public String getOtch() {
return otch;
}
public Date getDateofbirth() {
return dateofbirth;
}
public Long getGroupid() {
return groupid;
}
}

Code:
public class Group {
private Long groupid;
private String faculty;
public Group(){}
public void setGroupid(Long groupid) {
this.groupid=groupid;
}
public Long getGroupid() {
return groupid;
}
public void setFaculty(String faculty) {
this.faculty = faculty;
}
public String getFaculty() {
return faculty;
}
}

xmls:
Stud.hbm.xml

Code:
<hibernate-mapping>
<class name="test4.Student" table="students">
<id column="id" name="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<property column="FirstName" name="firstName" type="java.lang.String"/>
<property column="LastName" name="lastName" type="java.lang.String"/>
<property column="Otch" name="otch" type="java.lang.String"/>
<property column="DateofBirth" name="dateofBirth" type="java.util.Date"/>
<many-to-one name="group" column="groupid" class="test4.Group"/>
</class>
</hibernate-mapping>

Studgroups.hmb.xml
Code:
<hibernate-mapping>
<class name="test4.Group" table="studgroups">
<id column="groupid" name="groupid" type="java.lang.Long">
<generator class="increment"/>
</id>
<property column="faculty" name="faculty" type="java.lang.String"/>
<set name="studgroups" table="studgroups" lazy="false">
<key column="id"/>
<one-to-many class="test4.Student"/>
</set>
</class>
</hibernate-mapping>

configuration xml
Code:
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<mapping resource="test4/stud.hbm.xml"/>
<mapping resource="test4/studgroups.hbm.xml"/>
</session-factory>
</hibernate-configuration>

I'm trying to select data from DB using the following code:
Collection groups = Factory.getInstance().getgroupdao().getAllGroups();
Iterator iterator = groups.iterator();
while (iterator.hasNext()) {
Group grp = (Group) iterator.next();
System.out.println("группа : " + grp.getGroupid());
Collection students = Factory.getInstance().getstuddao().getStudentsByGroup(grp);
Iterator iterator2 = students.iterator();
while (iterator2.hasNext()) {
Student std = (Student) iterator2.next();
System.out.println("студент " + std.getLastname());
}
}

Could you help me, I have no idea why I get the following exception? thank you.
  • 1. Re: IllegalArgumentException occured while calling setter of
    796367 Explorer
    Currently Being Moderated
    797621 wrote:
    IllegalArgumentException occured while calling setter of test4.Group.groupid
    I assume that the offending call is made in Factory.getInstance().getgroupdao().getAllGroups() somewhere, or maybe you defined your DB table incorrectly. Heck, it could be a million different things... I'm just taking a wild guess.

    AND you know, someone has to tell you to use the code tags don't you?
  • 2. Re: IllegalArgumentException occured while calling setter of
    jduprez Pro
    Currently Being Moderated
    Hello,

    I'm sorry I don't know Hibernate (I just stumbled on this topic as it was unduely posted in the "Design and patterns" forum), but I see a couple of inconsistencies in your post (probably typos):
    - check the spelling of your mapping configuration files (hbm vs hmb)
    - the studgroup table has a "groupnumber" column, that doesn't appear in the mapping conf

    Also it would help if you posted the stack trace of the exception (so that we get an idea whether it is raised in the Hibernate machinery, presumably as a result of a misconfiguration, or from within your code).

    Eventually, it bears repeating: please use +
    + tags around your code to make your code and config readable to us wrinkled users, and please check the formatting in the preview tab, before posting.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points