我有实体:
@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...
}
我希望 TargetGroup、Customer、MessageTemplate 成为查询的结果。我的选择:
SELECT msg FROM SentMessage msg JOIN msg.targetGroup tg, msg.customer cust, msg.template temp WHERE ....
这是正确的,或者我应该怎么写?我想要所有实体的所有参数。谢谢!
编辑:我想按 TargetGroup 的名称、客户的名称和其他名称进行搜索,我应该如何在 WHERE 中写入?