Hi, all
i can't filter by parent property. h3 don't include filter restriction in sql where clause.
Hibernate version: 3 beta
Mapping documents:
<class name="test.Abc" table="ENT_ABC" discriminator-value="null">
<id name="id" type="java.lang.String" column="M_ID" unsaved-value="null" >
<generator class="uuid"/>
</id>
<discriminator formula="M_CLASS" type="string" not-null="true" insert="false"/>
<property name="revisionStatus" type="java.lang.Integer" column="M_SYS_STATUS" not-null="true" length="22"/>
<property name="prop" type="java.lang.String" column="M_PROP" not-null="true"/>
<property name="clazz" type="java.lang.Integer" column="M_CLASS" not-null="true"/>
<subclass name="test.SubClass2" discriminator-value="null">
<property name="sub2Prop" type="java.lang.String" column="M_SUB2_PROP"/>
<subclass name="test.SubClass21" discriminator-value="3">
<property name="sub21Prop" type="java.lang.String" column="M_SUB21_PROP"/>
</subclass>
<subclass name="test.SubClass22" discriminator-value="4">
<property name="sub22Prop" type="java.lang.String" column="M_SUB22_PROP"/>
</subclass>
</subclass>
<filter name="archiveFilter" condition="M_SYS_STATUS = :isArchive" />
<filter name="prop2" condition="M_SUB22_PROP = :prop" />
</class>
<filter-def name="archiveFilter">
<filter-param name="isArchive" type="integer"/>
</filter-def>
<filter-def name="prop2">
<filter-param name="prop" type="string"/>
</filter-def>
</code>
Code between sessionFactory.openSession() and session.close():
Session session = HibernateSession.getCurrentSession(); Transaction t = session.beginTransaction();
String query = "from SubClass22";
session.enableFilter("archiveFilter").setParameter("isArchive", new Integer(1)); session.createQuery(query).list();
session.enableFilter("prop2").setParameter("prop", "xxx"); session.createQuery(query).list();
t.commit(); session.close();
Full stack trace of any exception that occurs:
Name and version of the database you are using:
HSQLDB 1.7
The generated SQL (show_sql=true):
DEBUG SQL:290 - select subclass22x0_.M_ID as M_ID, subclass22x0_.M_SYS_COMMENT as M_SYS_CO2_0_, subclass22x0_.M_SYS_STATUS as M_SYS_ST3_0_, subclass22x0_.M_PROP as M_PROP0_, subclass22x0_.M_CLASS as M_CLASS0_, subclass22x0_.M_TYPE as M_TYPE0_, subclass22x0_.M_SUB2_PROP as M_SUB2_10_0_, subclass22x0_.M_SUB22_PROP as M_SUB2212_0_ from ENT_ABC subclass22x0_ where subclass22x0_.M_CLASS='4'
DEBUG SQL:290 - select subclass22x0_.M_ID as M_ID, subclass22x0_.M_SYS_COMMENT as M_SYS_CO2_0_, subclass22x0_.M_SYS_STATUS as M_SYS_ST3_0_, subclass22x0_.M_PROP as M_PROP0_, subclass22x0_.M_CLASS as M_CLASS0_, subclass22x0_.M_TYPE as M_TYPE0_, subclass22x0_.M_SUB2_PROP as M_SUB2_10_0_, subclass22x0_.M_SUB22_PROP as M_SUB2212_0_ from ENT_ABC subclass22x0_ where subclass22x0_.M_CLASS='4'
i would like see such generated sql:
select * from ent_abc where m_class = 4 and m_sys_status = 1
and if i filter by own property (sub22Prop)
h3 generate
select * from ent_abc where m_class = 4 and m_sub22_prop = 'blablabla'
2.same behavior if i use joined-subclass
3. could anyone point me where hibernate developers explaine why filtering not allowed to many-to-one, only one-to-many.
4. how can i create filetr and that filetr will filtering by list of values and generate such sql:
... where .. and (t.prop in ($first_value$, $second_value$, ... $last_value$))
if on development time i don't know count of params ?
thanks, Alexandr
|