Hibernate 3.3 と注釈を使用して複合主キーを持つオブジェクトを保存する際に問題があります。
私のキーは、ユーザーの一意の ID とデータベース生成のタイムスタンプで構成されています。
注釈を使用してこのキーをマップするにはどうすればよいですか? いくつかのリバース エンジニアリング ツールを使用しましたが、エンティティを保存しようとすると問題が発生します。
例:
@Entity
@Table(name = "ACTIVITY_LOG", schema = "WEB")
public class ActivityLog implements java.io.Serializable {
// Fields
private ActivityLogId id;
private SearchAuditRecord searchAuditRecord;
// Constructors
.....
// Property accessors
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "identifier", column = @Column(name = "IDENTIFIER", nullable = false, length = 11)),
@AttributeOverride(name = "createTimestamp", column = @Column(name = "CREATE_TIMESTAMP", insertable=false, updatable=false, nullable = false, length = 26)) })
public ActivityLogId getId() {
return this.id;
}
public void setId(ActivityLogId id) {
this.id = id;
}
.....
}
@Embeddable
public class ActivityLogId implements java.io.Serializable {
// Fields
private String identifier;
private Date createTimestamp;
// Constructors
/** default constructor */
public ActivityLogId() {
}
/** full constructor */
public ActivityLogId(String hrmisIdentifier, Date createTimestamp) {
this.identifier = identifier;
this.createTimestamp = createTimestamp;
}
// Property accessors
@Column(name = "IDENTIFIER", nullable = false, length = 11)
public String getIdentifier() {
return this.identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
@Column(name = "CREATE_TIMESTAMP",insertable= false, updatable= false, nullable = false, length = 26)
public Date getCreateTimestamp() {
return this.createTimestamp;
}
public void setCreateTimestamp(Timestamp createTimestamp) {
this.createTimestamp = createTimestamp;
}
}
ActivityLogID.createTimestamp がデータベースによって作成されていることを Hibernate に伝える必要があると思いますが、方法がわかりません。
現状では、これらのオブジェクトを保存しようとすると、次のようになります。
org.hibernate.exception.ConstraintViolationException:
could not insert: [ca.gc.rcmp.persistence.ActivityLog]........
Caused by: com.ibm.db2.jcc.am.fo: DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC= , DRIVER=3.57.82
これは、null 以外の列に null を入れることはできないと言っています。CreateTimestamp は、null である私のエンティティの唯一のフィールドです。
アドバイスをいただければ幸いです。
ありがとう!