Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@CreationTimestamp and @UpdateTimestamp don't work in Spring Kotlin [SPR-16257] #20804

Closed
spring-issuemaster opened this issue Dec 3, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Dec 3, 2017

cdxf opened SPR-16257 and commented

I tried with Java and it still works, but not with Kotlin. both use Spring Boot 2.0

Kotlin (even with @Temporal it doesn't work too):

@Entity
class Post(
        @get:NotBlank
        var name: String = "",
        val content: String = ""
) {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    val id: Int? = null
    @ManyToMany
    @Cascade(CascadeType.ALL)
    val tags: MutableSet<Tag> = mutableSetOf()

    @CreationTimestamp
    lateinit var createDate: Date


    @UpdateTimestamp
    lateinit var updateDate: Date

    fun addTag(tag: Tag) {
        this.tags.add(tag)
        tag.posts.add(this)
    }
}

The result:
!kotlin.png|thumbnail!

Java:

@Entity
public class Post {

    public Post(@NotBlank String name, String content) {
        this.name = name;
        this.content = content;
    }

    public void addTag(Tag tag) {
        this.tags.add(tag);
        tag.posts.add(this);
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    Integer id;
    @NotBlank
    String name;
    String content;
    @ManyToMany
    @JoinColumn(name="tags")
    @Cascade(CascadeType.ALL)
    public Set<Tag> tags = new HashSet();

    @CreationTimestamp
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created")
    Date createDate;
    @Column(name = "updated")
    @UpdateTimestamp
    Date updateDate;
}

The result:

!java.png|thumbnail!

Below is my sample project:
[^project.zip]


Affects: 5.0.2

Attachments:

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 3, 2017

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 26, 2018

Sébastien Deleuze commented

Ok thanks for the feedback, notice that Spring Framework reference documentation now provides guidance about this not straightforward behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.