2012-01-11 64 views
0

我试图在这里如何在Play框架中使用复合键?

http://docs.oracle.com/cd/B31017_01/web.1013/b28221/cmp30cfg001.htm

按照说明随着使用通用模型。我结束了一个主键类如下

import javax.persistence.Embeddable; 
import java.io.Serializable; 

@Embeddable 
public class DailyPK implements Serializable { 

    private int match_id; 
    private int user_id; 

    public int getUser_id() { 
     return user_id; 
    } 

    public void setUser_id(int user_id) { 
     this.user_id = user_id; 
    } 

    public int getMatch_id() { 
     return match_id; 
    } 

    public void setMatch_id(int match_id) { 
     this.match_id = match_id; 
    } 

    public int hashCode() { 
     return match_id * 1000000 + user_id; 
    } 

    public boolean equals(Object obj) { 
     if (obj == this) return true; 
     if (!(obj instanceof DailyPK)) return false; 
     if (obj == null) return false; 
     DailyPK pk = (DailyPK) obj; 
     return pk.match_id == match_id && pk.user_id == user_id; 
    } 
} 

我的模型类是如下不编译

public class Daily extends GenericModel { 

    @Id 
    DailyPK primaryKey; 


    public int round; 
    public int score; 


    public Daily(int round, int score) { 
     this.round = round; 
     this.score = score; 
    } 

    @EmbeddedId 
    public DailyPK getPrimaryKey() { 
     return primaryKey; 
    } 

    public void setPrimaryKey(DailyPK pk) { 
     primaryKey = pk; 
    } 

} 

我需要什么样的修改做什么呢?

回答

2

当延长GenericModel你需要重写_key方法

@Override 
public Object _key() { 
    return getPrimaryKey(); 
}