-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Composite primary key not work on postgresql
PostPosted: Wed Aug 28, 2013 6:41 am 
Newbie

Joined: Wed Aug 28, 2013 6:28 am
Posts: 1
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.