@UpdateTimestamp and @CreationTimestamp missing @Target annotation and breaking in Kotlin

Description

@UpdateTimestamp and @CreationTimestamp do not get applied to fields/getters/setters since they are missing the @Target annotation

Environment

Spring Boot v2.0.3.RELEASE, Hibernate Core {5.2.17.Final}, Hibernate Commons Annotations {5.0.1.Final}, org.hibernate.dialect.MySQL57InnoDBDialect, Kotlin 1.2.51

Activity

Show:
Guillaume Smet
July 15, 2018, 11:33 AM

Hi ,

I agree it would be better to have an @Target defined but AFAIK in Java, not defining an @Target is just authorizing using the annotation in a lot more places than it should be used.

Is Kotlin doing something specific with @Target? What's your issue exactly?

Yuanchu Xie
July 20, 2018, 2:08 PM

Hi Guillaume Smet,

Thanks for fixing this issue. The way Kotlin interops with Java is a bit funky. If you are declaring properties in a constructor, like this:

Without any @Target annotation, Kotlin only puts the annotation on the constructor argument and not the field. The decompiled Java code looks like this:

However, with the @Target annotation applied to the annotation interface, the decompiled code looks like this:

I am not exactly sure why it's done this way, but all the other Hibernate annotations work properly.

Guillaume Smet
July 20, 2018, 2:41 PM

Hum. I think it's a mistake on their part. Not defining @Target shouldn't lead to this behavior.

Anyway, it's fixed . Thanks for the report.

Assignee

Guillaume Smet

Reporter

Yuanchu Xie

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure