I have a Vaadin8 application and the following two classes.
(Classes simplified for readability)
Car Class:
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;
}
Car Leasing Duration Class:
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;
}
You have a car that can be leased multiple times, for a duration of time (startDatetime to endDatetime).
I want to create a ComboBox, with a list of all cars, except the ones that their leasing duration has expired. So I create a JPA Container from the Car class
EntityManager em = JPAContainerFactory.createEntityManagerForPersistenceUnit(HelpConstants.PERSISTENT_UNIT);
JPAContainer<Car> carContainer = JPAContainerFactory.makeReadOnly(Car.class, em);
I've tried something like this, which of course doesn't work
carContainer.addNestedContainerProperty("carLeasingDurationCollection.carLeasingDuration.endDatetime");
carContainer.addContainerFilter(new Not(new Compare.Greater("carLeasingDurationCollection.carLeasingDuration.endDatetime", new Date())));
I'm getting error for invalid property name.
Is there a way to filter this container based on the One to Many relationship that there is between Car and CarLeasingDuration? And if not, how would I go about doing that?
Thank you.