2013-07-11 25 views
2

在Scala編程使用註釋@JoinTable有一個errror註解@JoinTable如何使用Scala編程

我導入此

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中使用這個註釋,但沒有錯誤。如果有人知道答案,請在這裏分享。

與問候MILANO

回答

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