any idea how i could make delegated properties in ...
# spring
n
any idea how i could make delegated properties in kotlin work with jpa?
s
JPA is setting directly private fields I think, so I don't think that will work.
n
😞
thanks
t
I tried to use them and they don't really work. or it is weird, I will try today to create a sample repository with my findings
n
i abandoned this approach in favor of event listeners in hibernate
t
and I now figure you probably meant delegated properties https://kotlinlang.org/docs/reference/delegated-properties.html, I mean the delegation pattern https://kotlinlang.org/docs/reference/delegation.html
l
@nfrankel do you try
@get:Column(...)
?
n
@lex i didn’t
l
@nfrankel try it and tell us 🙂
n
i just changed my code to use event listeners i might do it but later i’m too lazy atm
besides, i’m thinking that since i’m using constructor arguments annotations are already on fields and you cannot mix-and-match fields’ and getters’ annotations
t
I think you need
@field:annotation
, otherwise kotlin puts the annotation on the constructor parameter
Ar least, I had that case with validation and data classes
l
I think is this case all mappings should be on getters
n
tbh, i didn’t use hibernate for a long time and i remember that it was a good practice to put annotations on attributes i don’t remember the reason, though 😅
l
@thanksforallthefish
@field
does not help in this case, because fields physically do not represented in class with delegation
m
have you looked into
@EntityListeners
?
n
i’m using spring, entity listeners cannot be injected by spring 😞 i’m using hibernate events directly
m
true. we use eclipselink events directly 🙂
looking at weaved jpa classes I see
Copy code
protected transient PropertyChangeListener _persistence_listener;
possibly this could be leveraged. but i suppose there’s no solution without getting hands dirty..