I have a class StaffSchedule which has mant to one relationship with another class Staff. See below:
Code:
<class name="StaffSchedule" table="TC_StaffSchedule">
.......
<many-to-one name="staffId" column="staffId"
class="test.Staff" not-null="true"/>
........
/class>
The class Staff has a PK called id. In my code I am trying to find all the schedules for a given staffId. See below:
Code:
List<StaffSchedule> staffScheduleList = session.createCriteria(StaffSchedule.class)
.add(Restrictions.eq("staffId", staffId)).list();
This is throwing an exception:
Code:
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of test.Staff.id
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
However if I change my many to one association as follows I get a different error.
Code:
<many-to-one name="staffId" column="staffId"
class="test.Staff" property-ref="id" not-null="true"/>
The default value of property-ref should be the PK of the Staff (id), so the property-ref should NOT have made any difference, but see below:
Code:
Service method 'public abstract java.util.List test.StaffSchedulerService.getAllSchedules(long)' threw an unexpected exception: java.lang.NullPointerException
....
Caused by: java.lang.NullPointerException
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:524)
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:3844)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:456)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:141)
...
I am confused! I am using Java 1.6 with Hibernate 3.5.3.
Any pointers?