[英]how to set date as primarykey in entity with hibernate
I have entity with 3 primary key That third is type of date and when i try to insert data in entity i encounter an error --> org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.util.Date 我有带有3个主键的实体,第三个是日期类型,当我尝试在实体中插入数据时遇到错误-> org.hibernate.id.IdentifierGenerationException:id的未知整数数据类型:java.util.Date
i found the solution for String but not for date type. 我找到了字符串的解决方案,但没有日期类型。
and this is my entity: 这是我的实体:
import javax.persistence.*;
import java.util.Date;
import java.util.List;
@Entity
public class PartyContactMech extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long partyId;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long contactMechPurposeId;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Date fromDate;
@Column
private Date usedSince;
@OneToMany(cascade = CascadeType.ALL)
private List<ContactMech> ContactMeches;
@OneToOne(cascade = CascadeType.ALL)
private ContactMechPurpose contactMechPurpose;
public Long getPartyId() {
return partyId;
}
public void setPartyId(Long partyId) {
this.partyId = partyId;
}
public Long getContactMechPurposeId() {
return contactMechPurposeId;
}
public void setContactMechPurposeId(Long contactMechPurposeId) {
this.contactMechPurposeId = contactMechPurposeId;
}
public Date getFromDate() {
return fromDate;
}
public void setFromDate(Date fromDate) {
this.fromDate = fromDate;
}
public Date getUsedSince() {
return usedSince;
}
public void setUsedSince(Date usedSince) {
this.usedSince = usedSince;
}
public List<ContactMech> getContactMeches() {
return ContactMeches;
}
public void setContactMeches(List<ContactMech> contactMeches) {
ContactMeches = contactMeches;
}
public ContactMechPurpose getContactMechPurpose() {
return contactMechPurpose;
}
public void setContactMechPurpose(ContactMechPurpose contactMechPurpose)
{
this.contactMechPurpose = contactMechPurpose;
}
}
anyone can help,thanks 任何人都可以帮助,谢谢
Try to remove @GeneratedValue(strategy = GenerationType.AUTO)
fromDate. 尝试从日期中删除
@GeneratedValue(strategy = GenerationType.AUTO)
。 GenerationType.AUTO
is for autoIncrement field. GenerationType.AUTO
用于autoIncrement字段。
Try like this 这样尝试
@Id
@GeneratedValue(strategy = AUTO)
@Column
private long id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.