我有一个 Vaadin8 应用程序和以下两个类。
(为便于阅读而简化的类)
车类:
public class Car implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "carId")
private Collection<CarLeasingDuration> carLeasingDurationCollection;
}
汽车租赁期限等级:
public class CarLeasingDuration implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Column(name = "start_datetime")
@Temporal(TemporalType.TIMESTAMP)
private Date startDatetime;
@Basic(optional = false)
@NotNull
@Column(name = "end_datetime")
@Temporal(TemporalType.TIMESTAMP)
private Date endDatetime;
@Basic(optional = false)
@NotNull
@Column(name = "cost")
private float cost;
@JoinColumn(name = "car_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Car carId;
}
您有一辆可以在一段时间内多次租用的汽车(startDatetime 到 endDatetime)。
我想创建一个组合框,其中包含所有汽车的列表,但租赁期限已过的汽车除外。所以我从 Car 类创建了一个 JPA Container
EntityManager em = JPAContainerFactory.createEntityManagerForPersistenceUnit(HelpConstants.PERSISTENT_UNIT);
JPAContainer<Car> carContainer = JPAContainerFactory.makeReadOnly(Car.class, em);
我已经尝试过这样的事情,这当然行不通
carContainer.addNestedContainerProperty("carLeasingDurationCollection.carLeasingDuration.endDatetime");
carContainer.addContainerFilter(new Not(new Compare.Greater("carLeasingDurationCollection.carLeasingDuration.endDatetime", new Date())));
我收到无效属性名称的错误。
有没有办法根据 Car 和 CarLeasingDuration 之间的一对多关系过滤这个容器?如果没有,我将如何去做呢?
谢谢你。