Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kotlin: some problems with arrays in annotations

I have a some problem in annotations:

Entity Table(uniqueConstraints = array(UniqueConstraint(columnNames = array("key", "userid")))) 
public class ...

In this case I get the following error:

Type inference failed. Expected type mismatch: found: kotlin.Array required: kotlin.String

There is no problems with uniqueConstraints = array(...) but Idea shows me error in columnNames = array(...)

I using hibernate-jpa-2.1-api-1.0.0.Final.jar


Workaround: Instead uniqueConstraints I using composite key (@javax.persistence.IdClass)

like image 602
Andrey Paslavsky Avatar asked Dec 09 '22 06:12

Andrey Paslavsky


2 Answers

This works for me:

@Table(uniqueConstraints = arrayOf(
        UniqueConstraint(columnNames = arrayOf("key", "key"))
))

Also for new version kotlin you may do that:

@Table(uniqueConstraints = [
    UniqueConstraint(columnNames = ["key", "key"])
])
like image 109
Alykoff Gali Avatar answered Dec 28 '22 01:12

Alykoff Gali


Use the spread operator:

UniqueConstraint(columnNames = *array("key", "userid"))
like image 27
Andrey Breslav Avatar answered Dec 28 '22 01:12

Andrey Breslav