Issue Type: Bug Bug
Affects Versions: 4.1.7
Assignee: Unassigned
Created: 04/Oct/12 3:26 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:

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

    @Id
    @GeneratedValue
    protected Long id;

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

}
@Entity
public class Item {

    @Id
    @GeneratedValue
    protected Long 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.

Project: Hibernate ORM
Priority: Minor Minor
Reporter: Christian Bauer
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