There are three entity like this:
{code:java} @Entity @Table(indexes = {}) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, include = "non-lazy") @SelectBeforeUpdate(true) @DynamicUpdate @DynamicInsert public class EStudent {
@Id @NotNull @Size(min = 36, max = 36) @Column(name = "id_") String id;
@Column String name;
@ManyToOne(cascade = { javax.persistence.CascadeType.REFRESH }, optional = false, fetch = FetchType.LAZY) EClass clazz;
@ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, mappedBy = "students") List<ETeacher> teachers; public String getId() { return id; } public void setId(String id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public EClass getClazz() { return clazz; }
public void setClazz(EClass clazz) { this.clazz = clazz; }
public List<ETeacher> getTeachers() { return teachers; }
public void setTeachers(List<ETeacher> teachers) { this.teachers = teachers; }
@PrePersist public void generateId(){ this.setId(UUID.randomUUID().toString()); } } { code}
{code:java} @Entity @Table(indexes = {}) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, include = "non-lazy") @SelectBeforeUpdate(true) @DynamicUpdate @DynamicInsert public class EClass {
@Id @NotNull @Size(min = 36, max = 36) @Column(name = "id_") String id;
@Column String name;
@OneToMany(cascade = javax.persistence.CascadeType.REFRESH, fetch = FetchType.LAZY,mappedBy = "clazz") @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, include = "non-lazy") List<EStudent> students;
@ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, mappedBy = "classes") List<ETeacher> teachers; public String getId() { return id; } public void setId(String id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public List<EStudent> getStudents() { return students; }
public void setStudents(List<EStudent> students) { this.students = students; }
public List<ETeacher> getTeachers() { return teachers; }
public void setTeachers(List<ETeacher> teachers) { this.teachers = teachers; }
@PrePersist public void generateId(){ this.setId(UUID.randomUUID().toString()); } } { code}
{code:java} @Entity @Table(indexes = {}) @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, include = "non-lazy") @SelectBeforeUpdate(true) @DynamicUpdate @DynamicInsert public class ETeacher{
@Id @NotNull @Size(min = 36, max = 36) @Column(name = "id_") String id;
@Column String name;
@ManyToMany(cascade = javax.persistence.CascadeType.REFRESH, fetch = FetchType.LAZY) @JoinTable(joinColumns = @JoinColumn(name = "teacher_id_"), inverseJoinColumns = @JoinColumn(name = "class_id_")) List<EClass> classes;
@ManyToMany(cascade = javax.persistence.CascadeType.REFRESH, fetch = FetchType.LAZY) @JoinTable(joinColumns = @JoinColumn(name = "teacher_id_"), inverseJoinColumns = @JoinColumn(name = "student_id_")) List<EStudent> students; public String getId() { return id; } public void setId(String id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public List<EClass> getClasses() { return classes; }
public void setClasses(List<EClass> classes) { this.classes = classes; }
public List<EStudent> getStudents() { return students; }
public void setStudents(List<EStudent> students) { this.students = students; }
@PrePersist public void generateId(){ this.setId(UUID.randomUUID().toString()); } } { code}
The JPQL: {code:sql} from com.yzt.microservice.core.ips.schema.demo.EStudent as eStudent inner join eStudent.clazz.teachers as eTeacher on eTeacher.name = 'Alice' {code}
This JPQL execute failure cause by "Unknown column 'eteacher3_.name_' in 'on clause'". The generate sql: {code:sql} SELECT estudent0_.id_ AS id_1_41_0_, eteacher3_.id_ AS id_1_72_1_, estudent0_.clazz_id_ AS clazz_id3_41_0_, estudent0_.name_ AS name_2_41_0_, eteacher3_.name_ AS name_2_72_1_ FROM estudent_ estudent0_ INNER JOIN eclass_ eclass1_ ON estudent0_.clazz_id_=eclass1_.id_ AND ( eteacher3_.name_='Alice') INNER JOIN eteacher_eclass_ teachers2_ ON eclass1_.id_=teachers2_.class_id_ INNER JOIN eteacher_ eteacher3_ ON teachers2_.teacher_id_=eteacher3_.id_ {code}
|
|