My code is like below, deleted unnessesary code:
Code:
@Entity
@Table(name = "role_permissions", schema = "sys")
@XmlRootElement
public class RolePermission implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected RolePermissionPK rolePermissionPK;
@Basic(optional = false)
@NotNull
@ElementCollection
@Column(name = "actions", nullable = false)
private List<String> actions;
..... // getter and setters
}
@Embeddable
public class RolePermissionPK implements Serializable {
@Basic(optional = false)
@NotNull
@Column(name = "role_id", nullable = false)
private int roleID;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 32)
@Column(name = "resource_key", nullable = false, length = 32)
private String resourceKey;
.... // getter and setters
}
The code above is generated by NetBeans 7.3.1,
these code works fine on MySQL 5.6. But, when I switched the database to Postgresql 9.2, It always errors with message below:
Quote:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build EntityManagerFactory
Caused by: org.hibernate.MappingException: Foreign key (FK_r9spbq02x6ymtne5r8wwv8kjy:role_permission_actions [role_permission])) must have same number of columns as the referenced primary key (role_permissions [resource_key,role_id])
I tried many solutions under many instructions, both of them have no effect. My Hibernate Version is 4.2, Spring version 3.2 . Is it a bug of Hibernate or my fault?