identicon
identicon

Reputation: 1

Spring Data JPA: CreationDate cannot be null

I declared the following entity in Spring Data Jpa:

@EntityListeners(AuditingEntityListener.class)
@Entity
@Table(name = "git_namespace")
@DynamicUpdate
public class GitNamespaceEntity {

    @CreatedDate
    @Temporal(TIMESTAMP)
    protected Date def_time;

    @LastModifiedDate
    @Temporal(TIMESTAMP)
    protected Date mod_time;

I try to update an entity in spring data jpa. But then I've got the following error:

NULL not allowed for column "DEF_TIME"

update git_namespace set def_time=?, mod_time=?,

I save a collection:

gitNamespaceRepository.saveAll(gitTransformationResult.getGitNamespaceList());

What can I do, to avoid the error?

Upvotes: 0

Views: 1597

Answers (2)

abdelkarim
abdelkarim

Reputation: 71

@CreationTimestamp
@Column(updatable = false)
private LocalDateTime createdAt;

@UpdateTimestamp
private LocalDateTime updatedAt;

Upvotes: 2

Brian
Brian

Reputation: 4408

This are how i annotate created_at and updated_at, note its in kotlin but might help

    @CreationTimestamp
    @Column(name = "created_at", updatable = false)
    val createdAt: Date = Date()

    @JsonProperty("updated_at")
    @UpdateTimestamp
    @Column(name = "updated_at")
    val updatedAt: Date = Date()

Upvotes: 0

Related Questions