我需要将所有事件都连接到用户。
我创建了一个模型来处理这种关系:
@Entity
public class Affiliated extends Model{
@OneToMany
private Bruker bruker;
@OneToOne
private Event event;
@Column(nullable = false)
private Calendar alarmTime = null;
public enum Status{
ATTENDING, MAYBE, NOT_ATTENDING, UNDECIDED
}
private Status status;
public Affiliated(){
this.status=Status.UNDECIDED;
}
public static Finder<Event, Affiliated> find = new Model.Finder<Event, Affiliated> (
Event.class, Affiliated.class
);
我试过这样做:
public static Result getEvents(){
if(Bruker.signedIn()) {
List<models.Event> eventList = models.Event.find.where().eq("creator", Bruker.find.byId(session("User"))).findList();
List<Affiliated> affiliatedList = models.Affiliated.find.where().eq("bruker", Bruker.find.byId(session("User"))).findList();
for (Affiliated i : affiliatedList) {
eventList.add(i.getEvent());
}
return Bruker.signedIn(ok(views.html.layoutHtml.render("MyEvents", views.html.Event.myEvents.render(eventList))));
}
return redirect(routes.Application.index().absoluteURL(request()));
}
但是当我尝试运行它时,它会为nullpointerException
返回affiliatedList
,即使返回空列表应该没有问题。
有关如何解决此错误的任何想法?
ps:&#34; bruker&#34;意味着&#34;用户&#34;用挪威语。