2011-11-06 84 views
0

我想創建這些情況: 用戶-------->用戶的速率約作者< ------------作者複合主鍵在休眠狀態下無法創建

所以我得到了類:

public class User implements UserDetails { 

     @Id 
    private String username; 
     (...) 
     @OneToMany(targetEntity=RateAth.class, mappedBy="user", cascade=CascadeType.ALL) 
     List<RateAth> authorRates 

public class Author { 

     @Id 
    private int id; 
    (...) 
     @OneToMany(targetEntity=RateAth.class, mappedBy="author", cascade=CascadeType.ALL) 
    private List<RateAth> authorRates; 

這裏是我的RateAth類:org.hibernate.MappingException:

@Entity 
@Table(name="users_authors_rate") 
public class RateAth { 
    @Id 
    private PK primaryKey; 
    private Integer rate; 
    private Date date; 
    private String username; 

    @Id 
    public PK getPrimaryKey() { 
     return primaryKey; 
    } 
    public void setPrimaryKey(PK primaryKey) { 
     this.primaryKey = primaryKey; 
    } 
    public Integer getRate() { 
     return rate; 
    } 
    public void setRate(Integer rate) { 
     this.rate = rate; 
    } 
    public Date getDate() { 
     return date; 
    } 
    public void setDate(Date date) { 
     this.date = date; 
    } 
    public User getUser() { 
     return primaryKey.getUser(); 
    } 
    public void setUser(User user) { 
     this.primaryKey.setUser(user); 
    } 

    public Author getAuthor() { 
     return primaryKey.getAuthor(); 
    } 
    public void setAuthor(Author author) { 
     this.primaryKey.setAuthor(author); 
    } 

    } 
@Embeddable 
class PK implements Serializable{ 
    @ManyToOne 
    @JoinColumn(name="username") 
    private User user; 
    @ManyToOne 
    @JoinColumn(name="author_id") 
    private Author author; 

    public User getUser() { 
     return user; 
    } 
    public void setUser(User user) { 
     this.user = user; 
    } 

    public Author getAuthor() { 
     return author; 
    } 
    public void setAuthor(Author author) { 
     this.author = author; 
    } 


} 

... 49多產生的原因:無法 確定類型:beans.Author,在表:users_authors_rate,用於 列:[org.hibernate.mapping.Column(作者)]在 org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:292)在 org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:276)at org.hibernate.mapping.Property.isValid(Property.java:207)at org.hibernate.mapping.PersistentClass.validate(PersistentClass。 java:458) at org.hibernate.mapping.RootClass.validate(RootClass.java:215)at org.hibernate.cfg.Configuration.validate(Configuration.java:1135)at org.hibernate.cfg.Configuration。 buildSessionFactory(Configuration.java:1320) at org.hibernate.cfg.AnnotationCo nfiguration.buildSessionFactory在 org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java在 org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)(AnnotationConfiguration.java:867) : 779) 在 org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) 在 有機.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCap ableBeanFactory.java:1417) ...... 56多個

回答