I have entities:
@Entity(name = "sent_message")
public class SentMessage extends AbstractEntity {
@ManyToOne(fetch = FetchType.LAZY)
private TargetGroup targetGroup;
@ManyToOne(fetch = FetchType.LAZY)
private Customer customer;
@ManyToOne(fetch = FetchType.LAZY)
private MessageTemplate template;
private Date sentDate;
getter.setter...
}
@Entity(name = "target_group")
public class TargetGroup extends AbstractEntity {
private String name;
private String description;
@ManyToMany(fetch = FetchType.LAZY)
private List<Customer> customers = new ArrayList<>();
getter.setter...
}
@Entity(name = "customer")
public class Customer extends AbstractEntity {
private String name;
private String email;
private String mobile;
@ManyToMany(mappedBy="customers", fetch = FetchType.LAZY)
private List<TargetGroup> targetGroups = new ArrayList<>();
@OneToMany(mappedBy = "customer", fetch = FetchType.LAZY)
private List<SentMessage> sentMessages = new ArrayList<>();
getter.setter...
}
@Entity(name = "message_template")
public class MessageTemplate extends AbstractEntity {
private String subject;
private String text;
@OneToMany(mappedBy = "template", fetch = FetchType.LAZY)
private List<SentMessage> sentMessages;
getter.setter...
}
I want the TargetGroup, Customer, MessageTemplate to be the result of the query. My SELECT:
SELECT msg FROM SentMessage msg JOIN msg.targetGroup tg, msg.customer cust, msg.template temp WHERE ....
Is that correct, or how should I write it? I want all the parameters from all entities. Thank you!
EDIT: I want to search by the name of the TargetGroup, the name of the Customer, and others, how should I write it in the WHERE??