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-projects-issues opened this issue Dec 3, 2017 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: invalid An issue that we don't feel is valid

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Dec 3, 2017

cdxf commented

I resolved this problem using use-site target as the link below:
https://stackoverflow.com/questions/47617726/creationtimestamp-and-updatetimestamp-dont-work-in-kotlin/47621831#47621831

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues 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.

@spring-projects-issues spring-projects-issues added type: bug A general bug status: invalid An issue that we don't feel is valid in: data Issues in data modules (jdbc, orm, oxm, tx) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

2 participants