In 3.1 final I was using the following with success:
class to be used as mapped component-id:
Code:
public class HistoryId implements Serializable {
private Object id;
private Date validFrom;
... equals() and hashCode()
... getters and setters
}
relevant mapping document part:
Code:
<class name='AbstractBenchmark' entity-name='com.csg.pmnet.se.model.AbstractBenchmarkHistory'
table='se_benchmark_hist'>
<composite-id mapped="true" class="com.csg.pmnet.model.HistoryId">
<key-property name="id" type="long"/>
<key-property name="validFrom" type="imm_timestamp" />
</composite-id>
.... rest omitted
I don't think the fact that I use an alternative entity name here is relevant, but I didn't try it out.
Now I execute the following HQL query:
Code:
from com.csg.pmnet.se.model.BenchmarkHistory where id = :id and validFrom <= :date and :date < validTo
Note: I'm not really using the composite-id here (i.e. not using session.get(AbstractBenchmark.class, new HistoryId(x,y)), but simply executing a query.
In 3.1 final all is OK, but in 3.1.1 and later I get an error:
Quote:
org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.csg.pmnet.model.HistoryId.id
.
Debugging into Hibernate, I notice that in org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValue (line 121 in version 3.1.2):
Code:
public Object getPropertyValue(Object component, int i)
throws HibernateException {
return getters[i].get( component );
}
The getter for field "id" is no longer called for a component of type HistoryId, but for a "component" of type Long. So instead getting the field calling HistoryId.id (correct) it tries to fetch the field Long.id, which obviously fails.
I strongly suspect a new bug here and have downgraded to version 3.1 final for the time being.
Am I using the mapped composite-id wrongly, or do we really have a bug here?
Edited, appended: no answers yet, should I file a bug in JIRA?