我花了數小時尋找如何解決這個問題。當我試圖從小孩那裏得到父母的所有,但它的id字段是空的。這沒有意義。我使用PlayFramework 2.0.4,如果這可能表明任何東西(除了可怕的框架選擇)。JPA @ManyToOne字段爲空
TRoute.java(父)
@Entity
@Table(name="routes")
public class TRoute extends Model {
@Id
public String route_id;
public String agency_id;
@Constraints.Required
public String route_short_name;
@Constraints.Required
public String route_long_name;
public String route_desc;
@Constraints.Required
public String route_type;
public String route_url;
public String route_color;
public String route_text_color;
@OneToMany(mappedBy="troute")
public List<Trip> trips;
public static Finder<String, TRoute> find = new Finder(
String.class, TRoute.class
);
}
Trip.java(子)
@Entity
@Table(name="trips")
public class Trip extends Model {
@Constraints.Required
public String route_id;
@Constraints.Required
public String service_id;
@Id
public String trip_id;
public String trip_headsign;
public String direction_id;
public String block_id;
public String shape_id;
@ManyToOne
@JoinColumn(name="route_id")
public TRoute troute;
public static List<Trip> byRouteId(String route_id) {
List<Trip> trips =
Trip.find
.where().like("route_id", route_id)
.findList();
return trips;
}
public static Finder<String, Trip> find = new Finder(
String.class, Trip.class
);
}
你的日誌顯示了什麼?你看到父級的SQL提取? –
我不是那種在Java中經歷過的。有沒有辦法查看由Play框架執行的SQL查詢? – heroix