This one is quite obscure, the problem is most likely in BinderHelper#createSyntheticPropertyReference().
A many-to-one foreign key association that doesn't reference a primary key, but a unique key:
@Entity
@Table(name = "USERS")
public class User {
@Id
@GeneratedValue
protectedLong id;
@NotNull
@Column(unique = true)
protectedString customerNr;
}
@Entity
public class Item {
@Id
@GeneratedValue
protectedLong id;
@NotNull
@ManyToOne
@JoinColumn(name = "SELLER_CUSTOMERNR",
referencedColumnName = "CUSTOMERNR")
protected User seller;
}
Throws an exception when you query Items:
java.lang.ClassCastException: org.jpwh.model.complexschemas.naturalforeignkey.User cannot be cast to java.io.Serializable
at org.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:157)
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2807)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1545)
If you remove the "referencedColumnName" attribute, the binding works. Note that this is one of those rare use cases for "property-ref" in XML binding.
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