复合ID及其在JPA中的生成

时间:2012-03-09 11:01:24

标签: java jpa

我想使用ID

之类的自定义类
@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  
}  

不起作用。价值没有产生。任何想法,如何为composite-id生成ID?

1 个答案:

答案 0 :(得分:0)

Id类必须是Serializable并实现hashCode和equals