Hi!
I try to create iterator on Students, but I have wrong results and wrong generated SQL:
Code:
Query q = session.createQuery("from " + Student.class.getName() + " bo where bo.removed=:removed or (bo.archiveRelation is not empty and bo.archiveRelation.record.creationDate < :beforeDate)");
q.setParameter("removed", false);
q.setParameter("beforeDate", beforeDate);
return q.iterate();
But when I execute this HQL, I have the following SQL:
Code:
select
student0_.UUID as col_0_0_
from
TBL_BO student0_
inner join
TBL_UNI_PERSON_ROLE student0_1_
on student0_.UUID=student0_1_.PersonRole_UUID
inner join
TBL_UNI_STUDENT student0_2_
on student0_.UUID=student0_2_.Student_UUID,
AR_STUDENT studentarc2_,
ARB_RECORD uniarchent3_
where
student0_.discr='TBL_UNI_STUDENT'
and student0_.UUID=studentarc2_.targetUUID
and studentarc2_.recordUUID=uniarchent3_.UUID
and (
student0_.removed=?
or (
exists (
select
studentarc1_.targetUUID
from
AR_STUDENT studentarc1_
where
student0_.UUID=studentarc1_.targetUUID
)
)
and uniarchent3_.creationDate<?
)
I don't understand why this lines generates:
Code:
and student0_.UUID=studentarc2_.targetUUID
and studentarc2_.recordUUID=uniarchent3_.UUID
And when I execute this query, I have a 703 entries, but when I execute this HQL: "from " + Student.class.getName() + " bo where bo.removed=:removed", I have a 7000 entries. I think that resulting SQL is wrong and don't understand why OR condition reduce result enties.
I have not so good mappings, using one-to-one relations. They are presented below.
This is student mapping:
Code:
<hibernate-mapping package="ru.naumen.uni.bobjects.student">
<subclass name="ru.naumen.unistudent.bobjects.student.Student"
discriminator-value="TBL_UNI_STUDENT" extends="ru.naumen.uni.bobjects.uniperson.PersonRole"
lazy="false" >
<one-to-one name="archiveRelation"
class="ru.naumen.unistudent.bobjects.student.StudentArchive" outer-join="false" />
<join table="TBL_UNI_STUDENT" fetch="select">
<key column="Student_UUID" foreign-key="FK_CorePerson_Student" />
..(Student attributes)..
</join>
</subclass>
</hibernate-mapping>
This is StudentArchive(one-to-one with Student) mapping:
Code:
<hibernate-mapping>
<class name="ru.naumen.unistudent.bobjects.student.StudentArchive"
table="AR_STUDENT" lazy="false" discriminator-value="StudentArchive">
<cache usage="read-write" />
<id name="targetUUID" type="string" column="targetUUID" length="32">
<generator class="foreign">
<param name="property">target</param>
</generator>
</id>
<discriminator column="discr" type="string" length="255" not-null="true" />
<one-to-one name="target"
class="ru.naumen.unistudent.bobjects.student.Student" foreign-key="FKSTUDENTTID" constrained="true" />
<many-to-one name="record"
class="ru.naumen.uni.archive.core.UNIArchEntryRecord" foreign-key="FKSTUDENTRID">
<column name="recordUUID" index="iSTUDENTRID" />
</many-to-one>
<property name="eprocEndDate" column="eprocenddate_" type="integer" />
<property name="personalNumber" column="personalnumber_"
type="integer" />
<property name="studentPersonalNumber" column="studentpersonalnumber_"
type="string" />
<many-to-one name="typeOfArchive" foreign-key="FK_ARCH_STUD_TYPE_ARCH"
index="IDX_STUD_ARCH_TYPE_ARCH" class="ru.naumen.uni.catalogs.archive.TypeOfArchiveCatalogItem"
outer-join="false" not-null="true" />
</class>
</hibernate-mapping>
This is UNIArchEntryRecord mapping(one-to-one with StudentArchive):
Code:
<hibernate-mapping>
<class name="ru.naumen.uni.archive.core.UNIArchEntryRecord" table="ARB_RECORD" lazy="false">
<id name="UUID" type="string" column="UUID" length="32">
<generator class="uuid" />
</id>
<property name="creationDate" type="timestamp" not-null="true" />
<property name="comment" column="comment_" type="ru.naumen.core.util.TrimmedString" length="2048" />
</class>
</hibernate-mapping>