无法访问@OneToOne映射实体

时间:2012-11-08 14:27:45

标签: templates scala playframework-2.0 ebean

我的数据模型:

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模板中,我希望获得一个足球游戏领域:

@(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 ompilation failed   [info]将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 \ tourss.template.scala:37:变量footballTour in class Tour   不能在模特中加入.Tour [错误]   “” “),显示(SEQ Any),format.raw / 8.11 /(” “”     - “”“),显示(Seq Any),format.raw / 8。   35 /(“”“[错误]

1 个答案:

答案 0 :(得分: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中,默认情况下,在未指定的情况下,字段是私有的。