My data model:
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);
}
}
My action(just to show that I’m fetching “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));
}
In scala template I want to acess footballTour field of Tour:
@(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>
}
And have error at compilation time:
[error] one error found [error]
{file:/C:/Users/pc/prog/}prog/compile:compile: C ompilation failed
[info] Compiling 1 Scala source to C:\Users\pc\prog\target\scala-2.
9.1\classes… [error] C:\Users\pc\prog\target\scala-2.9.1\src_managed\main\views\
html\tours.template.scala:37: variable footballTour in class Tour
cannot be acce ssed in models.Tour [error]
“””),display(SeqAny),format.raw/8.11/(“””
– “””),display(SeqAny),format.raw/8.
35/(“”” [error]
The field
genericTourof theFootballTourclass should be public:In java, by default, in not specified, the fields are private.