I have an Play2 application using eBean integrated with PostgreSQL database.
Basically I have a model TripRequest
that as a list of Passenger
s . The use case is "A trip has several passengers".
For the TripRequest
I have this model:
@Entity
public class TripRequest extends Model {
enum Status {
OPEN,
PROCESSING,
CLOSED,
CANCELLED
}
@Id
private UUID id;
@ManyToOne
@Column(nullable = false)
private User owner;
@OneToMany(mappedBy = "tripRequest")
@JoinTable(name = "trip_passengers")
private List<Passenger> passengers;
(... other fields, getters and setters ...)
And this is my Passenger
model:
@Entity
@Table(name = "trip_passenger")
public class Passenger extends Model {
@ManyToOne(cascade = CascadeType.ALL)
private TripRequest tripRequest;
@Column(nullable = false)
private String name;
(... other fields, getters and setters)
So, I create a new instance of TripRequest
, several instances of Passenger
and set that list as the passengers of TripRequest
instance.
Problem is that when I do tripRequest.save()
everything in the main instance (TripRequest
) gets saved but the relations are not (so the passengers list).
I read in the documentation and examples and everything is pointing me to the CascadeType.ALL
in the @ManyToOne
annotation but no "luck" at all
EDIT: if you think the complete classes are useful please let me know as I can post them. Just decided to keep the example short so I trimmed them.
@OneToMany
instead? – Vesicatory