2012-03-09 62 views
2

代我想使用自定義的類象ID複合ID及其在JPA

@javax.persistence.Embeddable 
class ObjectID impements Serializable{ 
private Long value;  
    //setters, getters and other 
} 

這裏被映射類

@Entity 
@IdClass(ObjectID.class) 
public class Country implements Serializable 
{ 
    @Id 
    @AttributeOverride(name = "value", column = @Column(name = "id")) 
    @SequenceGenerator(name = "CountrySequenceGenerator", 
         sequenceName = "lab_country_seq") 
    @GeneratedValue(strategy = GenerationType.SEQUENCE, 
        generator = "CountryCountryGenerator") 
    private ObjectID value; 
    // setters, getters, fields 
} 

不工作。沒有產生價值。任何想法,我怎樣才能生成複合ID的ID?

+0

什麼是CountryCountryGenerator? – wallenborn 2012-03-09 15:38:54

+0

「複合ID」與單個字段?這個組合怎麼樣?複合id有多個字段 – DataNucleus 2012-03-09 16:35:20

回答

0

Id類必須是Serializable並實現hashCode並等於

+0

我擁有所有這些在我ObjectID類。 – Ilya 2012-03-09 11:36:09

+0

請參見[複合ID及其在JPA中的生成](http://stackoverflow.com/q/9632942/651140) – 2012-03-09 11:37:26

+2

它鏈接在「this」 – Ilya 2012-03-09 11:39:34