获取org.hibernate.id.IdentifierGenerationException:在调用save()之前必须手动分配此类的ID

时间:2015-10-29 09:46:57

标签: java hibernate

Oct 29, 2015 2:29:48 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/globeconnect] threw exception [Request processing failed; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.globetouch.business.entities.DummyData] with root cause
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.globetouch.business.entities.DummyData

@Entity
@Table(name="DUMMY_DATA")
public class DummyData {
    @Id
    @Column(name="ICCID")
    private String ICCID;
    @Column(name="IMSI")
    private String IMSI;



create table DUMMY_DATA(
   ICCID VARCHAR(255),
   IMSI  VARCHAR(255),
   PRIMARY KEY (ICCID)
); 

我收到以下异常。我正在从文件中读取内容并保存在数据库中。 ICCID值将从文件中给出。其实我将文件内容值设置为ICCID,你可以帮我解决我的错误。

1 个答案:

答案 0 :(得分:0)

Stacktrace非常明显。您必须手动设置ID或在@GeneratedValue之上添加ICCID注释:

@SequenceGenerator(name = "yourSEQ", sequenceName = "your_id_seq")
@Id
@Column(name = "ICCID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "yourSEQ")
private String ICCID;

当然,您必须在数据库上创建your_id_seq序列。