Change By: Christian Bauer (04/Oct/12 3:30 AM)
Description: 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:

{code}

@Entity
@Table(name = "USERS")
public class User {

    @Id
    @GeneratedValue
    protected Long id;

    @NotNull
    @Column(unique = true)
    protected String customerNr;

}
{code}

{code}
@Entity
public class Item {

    @Id
    @GeneratedValue
    protected Long id;

    @NotNull
    @ManyToOne
    @JoinColumn(name = "SELLER_CUSTOMERNR",
        referencedColumnName = "CUSTOMERNR")
    protected User seller;
}
{code}

Throws an exception when you query Items:

{code}
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)
{code}

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.
Summary: Wrong binding  for  of  @ManyToOne  with referencedColumnName  for non-PK associations
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