0

我的数据模型:

public class Tour extends Model {    
    @Id
    public Integer id;

    @ManyToOne
    public Sport sport;

    @OneToOne(mappedBy="genericTour")
    FootballTour footballTour;

    @OneToOne(mappedBy="genericTour")
    TennisTour tennisTour;

    public static Finder<Integer, Tour> find(){
        return new Finder<Integer,Tour>(Integer.class,Tour.class);
    }
}

public class FootballTour extends Model {

    @Id
    public Integer id;

    @OneToOne
    Tour genericTour;

    public static Finder<Integer, FootballTour> find(){
        return new Finder<Integer,FootballTour>(Integer.class,FootballTour.class);
    }

}

我的行为(只是为了表明我正在获取“footballTour”):

  public static Result getToursBySportTag(String sportTag){

      Query query = Tour.find().fetch("sport").fetch("footballTour");
      List<Tour> finedTours =  query.where().eq("tag", sportTag).findList();

      return ok(tours.render(finedTours));

  }

在 scala 模板中,我想访问巡回赛的 footballTour 领域:

@(tours: List[Tour])
@main("Football tours") {
<h1>Football tours List</h1>
<dl>
@for(tour <- tours) {
<dt>
<a href="@routes.Application.tour(tour.id)">
@tour.footballTour.id
</a>
</dt>
}
</dl>
}

并在编译时出错:

[错误] 发现一个错误 [错误] {file:/C:/Users/pc/prog/}prog/compile:compile: C 编译失败 [信息] 将 1 个 Scala 源编译到 C:\Users\pc\prog\target \scala-2。9.1\classes... [错误] C:\Users\pc\prog\target\scala-2.9.1\src_managed\main\views\ html\tours.template.scala:37:类 Tour 中的变量 footballTour 不能访问ssed in models.Tour [error] """), display (Seq Any ),format.raw/ 8.11 /(""" - """), display (Seq Any ),format.raw/ 8. 35 /( “““ [错误]

4

1 回答 1

3

genericTour类的字段FootballTour应该是公共的:

public class FootballTour extends Model {

    @Id
    public Integer id;

    @OneToOne
    public Tour genericTour;  // <<<<< Here !!

    public static Finder<Integer, FootballTour> find(){
        return new Finder<Integer,FootballTour>(Integer.class,FootballTour.class);
    }

}

在java中,默认情况下,在未指定的情况下,字段是私有的。

于 2012-11-08T14:31:17.913 回答