Мои объекты:
Код: Выделить всё
@Table(name = "SPM_SECTION", schema = "TEST")
@GenericGenerator(name = "MODSEC_ID.GEN", strategy = "uuid2")
public class ModuleSection implements Serializable {
private AcademicClass academicClass;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CLASS_ID")
public AcademicClass getAcademicClass() {
return academicClass;
}
public void setAcademicClass(AcademicClass academicClass) {
this.academicClass = academicClass;
}
}
@Entity
@GenericGenerator(name = "AC_CLASS_ID.GEN", strategy = "uuid2")
@Where(clause="1=1")
@FilterDef(name= Resources.SECURITY_FILTER_NAME, parameters={@ParamDef(name=Resources.SECURITY_FILTER_PARAMETER, type="string")})
@Filter(name=Resources.SECURITY_FILTER_NAME, condition = "DISCRIMINATOR_ID in (:"+Resources.SECURITY_FILTER_PARAMETER+")")
@Table(name = "ACADEMIC_CLASS", schema = "TEST", uniqueConstraints = @UniqueConstraint(columnNames = {"OUS_ID", "YEAR_ID",
"PERIOD_ID", "SHIFT_ID", "SEMESTER", "CODE" }))
public class AcademicClass implements java.io.Serializable {
//I tried by having the association here, i also tried without it.
private Set sections = new HashSet(0);
@OneToMany(fetch = FetchType.LAZY, mappedBy = "academicClass")
public Set getSections() {
return this.sections;
}
public void setSections(Set sections) {
this.sections = sections;
}
}
Когда я выполняю такой запрос:< /p>
Код: Выделить всё
em.createQuery("select acc from AcademicClass acc ...........", AcademicClass.class)
.getResultList();
Код: Выделить всё
em.createQuery("select ms from ModuleSection ms join ms.academicClass acc", AcademicClass.class)
.getResultList();
Академический класс в объекте ModuleSection имеет значение NULL, но у меня также есть другие объекты, не равные нулю, в приведенном выше случае. не работает.
Я также безуспешно пытался применить свойство @Filter или @FilterJoinTable в разделе модуля:
Код: Выделить всё
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CLASS_ID")
@Filter(name=Resources.SECURITY_FILTER_NAME, condition = "DISCRIMINATOR_ID in (:"+Resources.SECURITY_FILTER_PARAMETER+")")
@FilterJoinTable(name=Resources.SECURITY_FILTER_NAME, condition = "DISCRIMINATOR_ID in (:"+Resources.SECURITY_FILTER_PARAMETER+")")
public AcademicClass getAcademicClass() {
return academicClass;
}
Предназначены ли фильтры для фильтрации только объекта в предложении from? применяется ли фильтр к объектам соединения?
Если я хочу реализовать вышеизложенное, следует ли мне также добавить DISCRIMINATOR_ID в ModuleSection и добавить фильтр к этому объекту, начиная запрос оттуда?
Подробнее здесь: https://stackoverflow.com/questions/639 ... oin-entity