Issue Type: Improvement Improvement
Affects Versions: 4.1.6
Assignee: Unassigned
Components: core
Created: 28/Jan/13 9:47 PM
Description:

I was getting `IllegalArgumentException: object is not an instance of declaring class`.

It turned to be a mapping error (as usually).
But the message I was getting was a bit confusing:

org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of org.jboss.essc.web.model.ProductCustomField.id

It had nothing to do with the id property. It was due to wrong type in
`@MapKeyClass(FooBar.class)`.

What made it really tricky was that when reading, this didn't matter (probably not used?); only when writing back to DB, `id` was inspected in a call to `ForeignKeys.isTransient()`.

I can see a nice point 4 levels back in the call stack where it could be nice to check/warn if (or at least `assert` that) the entity and expected entity type are the same:

In `MapType.replaceElements()`

Object key = cp.getIndexType().replace( me.getKey(), null, session, owner, copyCache );

`cp.indexType.associatedEntityName` knows that `me.getKey()` type doesn't match.

So perhaps `replace()` could check?

And in general, in places where user-specified classes are used, Hibernate could check for such errors, it would make it much easier to debug such errors.
@MapKeyClass(ProductCustomField.class)

Project: Hibernate ORM
Priority: Minor Minor
Reporter: Ondra Žižka
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira