2

在 Scala 编程中使用 Annotation @jointable 时出错

我导入这个

import javax.persistence.JoinTable

编码

@BeanProperty
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "LW_USER_ROLE", joinColumns = { @JoinColumn(name = "USERACCOUNT_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
                Here got the compilation error ---^                                                            ^------ and here
var roles:List[Role]

编译错误

Multiple markers at this line
    - expected start of definition
    - annotation argument needs to be a constant; found: { <empty>; (){<error>} }
     {<error>}
    - type mismatch; found : Unit required: Array[javax.persistence.JoinColumn]
    - expected start of definition
    - annotation argument needs to be a constant; found: { <empty>; (){<error>} }
     {<error>}
    - type mismatch; found : Unit required: Array[javax.persistence.JoinColumn] 

我在java中使用了这个注释,但没有错误..如果有人知道答案,请在这里分享。

关于米兰

4

1 回答 1

1

您必须将元注释添加到注释类型。对于 JoinColumn 试试这个:

import annotation.target.field

@(JoinColumn @field)(name = "USERACCOUNT_ID")

您还可以定义类型别名,例如:

object MyAnnotations {
  type JoinColumn = jpa.JoinColumn @field
}

然后导入这些注释而不是原始注释。另见:https ://issues.scala-lang.org/browse/SI-3421

于 2013-07-11T17:45:10.343 回答