注释@JoinTable如何使用scala编程

时间:2013-07-11 04:28:07

标签: spring hibernate scala

在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]

汇编ERROR

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中使用这个注释但是没有错误..如果有人知道答案,请在这里分享。

关于MILANO

1 个答案:

答案 0 :(得分:2)

您必须在注释类型中添加元注释。对于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