我在注释中遇到了一些问题:
Entity Table(uniqueConstraints = array(UniqueConstraint(columnNames = array("key", "userid"))))
public class ...
在这种情况下,我收到以下错误:
类型推断失败。预期类型不匹配:发现: kotlin.Array required:kotlin.String
uniqueConstraints = array(...)没有问题,但是Idea在 columnNames = array(...)
中显示错误我使用 hibernate-jpa-2.1-api-1.0.0.Final.jar
解决方法:而是使用复合键(@ javax.persistence.IdClass)的uniqueConstraints
答案 0 :(得分:4)
这对我有用:
@Table(uniqueConstraints = arrayOf(
UniqueConstraint(columnNames = arrayOf("key", "key"))
))
对于新版kotlin,您可以这样做:
@Table(uniqueConstraints = [
UniqueConstraint(columnNames = ["key", "key"])
])
答案 1 :(得分:2)
UniqueConstraint(columnNames = *array("key", "userid"))
答案 2 :(得分:0)
今天我自己也在挣扎。以下代码段适用于最新版本的Kotlin:
@ApiResponses(value = *arrayOf(
ApiResponse(code = 403, message = "Unauthorized"),
ApiResponse(code = 404, message = "Item not found")))
或更短的选项:
@ApiResponses(
ApiResponse(code = 403, message = "Unauthorized"),
ApiResponse(code = 404, message = "No active snapshots"))
如果带有数组的注释定义为:
public @interface ApiResponses {
ApiResponse[] value();
}