看起来当scala 2.8.0发布时,我们可以在持久层中使用嵌套的@annotations。但是如何?任何人都可以将其从Java转换为Scala吗?谢谢。

@NamedQueries({
    @NamedQuery(name = "findAll", query="select p from Person p"),
    @NamedQuery(name = "findTheOne",
          query="select p from Person p where p.name = 'Neo'")
})

最佳答案

您必须将元素包装在Array()中,并像构造函数调用一样编写嵌套的批注:

@NamedQueries(Array(
    new NamedQuery(name = "findAll", query="select p from Person p"),
    new NamedQuery(name = "findTheOne",
          query="select p from Person p where p.name = 'Neo'")
))

10-06 09:04