-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SubCriteria problems
PostPosted: Fri Sep 02, 2005 1:06 pm 
Newbie

Joined: Tue Aug 09, 2005 4:48 am
Posts: 6
Hi everybody, I have some problem with criteria searches. I have a Elevator instance associated to an Address instance.
In my hbm file I have mapped Address inside Elevator class as component.

Now when I build a criteria, to search a iLike expression in Elevator.Address.Street, using subcrietia I obtain a QueryException : could not resolve property: street of: it.linksystem.csai.model.Elevator

It seems that subCriteria doesn't work right and it search Street property directly in Elevator class

Follows hbm file and Search code

Hibernate version: 3

Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="it.linksystem.csai.model.User" polymorphism="explicit" table="Users">
  <id name="id" type="java.lang.Long">
   <generator class="native"/>
  </id>
  <discriminator force="false" insert="true" not-null="false">
   <column length="12" name="Role" not-null="true"/>
  </discriminator>
  <property name="phone"/>
  <property name="password"/>
  <property name="surname"/>
  <property name="cellular">
   <column name="cellular"/>
  </property>
  <property name="language"/>
  <property name="username">
     <column name="username" not-null="true" unique="true"/>
  </property>
  <property name="email"/>
  <property name="ac">
   <column name="ac" not-null="true"/>
  </property>
  <property name="name"/>
  <component name="address">
   <property name="street"/>
   <property name="cap">
    <column name="cap"/>
   </property>
   <property name="city">
    <column name="city"/>
   </property>
   <property name="number"/>
   <property name="province"/>
   <property name="country"/>
  </component>
  <bag name="societies" table="Employes" lazy="false">
   <key>
    <column name="user_id"/>
   </key>
   <many-to-many class="it.linksystem.csai.model.Society" column="society_id" lazy="false" />
  </bag>
  <property name="accountState">
    <column name="enabled"/>
  </property>
  <subclass discriminator-value="ROLE_O" name="it.linksystem.csai.model.Operator"/>
  <subclass discriminator-value="ROLE_T" name="it.linksystem.csai.model.Technician">
   <property name="techLevel"/>
   <bag name="zones" table="Turns"  lazy="false">
    <key>
     <column name="technician_id"/>
    </key>
    <many-to-many class="it.linksystem.csai.model.Zone" column="zone_id"/>
   </bag>
   <property name="state"/>
  </subclass>
  <subclass discriminator-value="ROLE_I" name="it.linksystem.csai.model.Inspector">
   <property name="entity"/>
   <bag name="reports" table="AssignedReports">
    <key>
     <column name="inspector_id" not-null="true"/>
    </key>
    <many-to-many class="it.linksystem.csai.model.ReportModel" column="report_id"/>
   </bag>
  </subclass>
  <subclass discriminator-value="ROLE_S" name="it.linksystem.csai.model.SuperUser"/>
  <subclass discriminator-value="ROLE_A" name="it.linksystem.csai.model.Admin"/>
</class>
<class name="it.linksystem.csai.model.Society" table="Societies" lazy="false">
  <id name="id">
   <generator class="native"/>
  </id>
  <property name="phone"/>
  <property name="maxTechnicians"/>
  <property name="piva"/>
  <property name="email"/>
  <property name="maxOperators"/>
  <property name="fax"/>
  <property name="name"/>
  <property name="maxElevators"/>
  <property name="maxReports"/>
  <property name="state"/>
  <component name="address">
   <property name="cap"/>
   <property name="city"/>
   <property name="country"/>
   <property name="number"/>
   <property name="province"/>
   <property name="street"/>
  </component>
</class>
<class name="it.linksystem.csai.model.search.Constraint" table="Constraints">
<id name="id">
   <generator class="native"/>
</id>
<property name="operator"/>
<property name="propertyField"/>
<property name="propertySubField"/>
<property name="composite"/>
</class>
<class name="it.linksystem.csai.model.ReportModel" table="ReportModels">
  <id name="id">
   <generator class="native"/>
  </id>
  <many-to-one name="owner">
   <column name="society"/>
  </many-to-one>
  <property name="name"/>
  <property name="maxResults"/>
  <property name="orderField"/>
  <property name="startIndex"/>
  <property name="subject"/>
  <property name="paging"/>
  <property name="ordered"/>
  <property name="asc">
     <column name="ascOrder" />
  </property>
  <bag name="constraints" table="ReportConstraints" lazy="false">
   <key>
    <column name="report_id"/>
   </key>
   <many-to-many class="it.linksystem.csai.model.search.Constraint" column="constraint_id" lazy="false" />
  </bag>
</class>
<class name="it.linksystem.csai.model.Elevator" table="Elevators">
  <id name="id">
   <generator class="native"/>
  </id>
  <property name="brand"/>
  <property name="sn"/>
  <property name="entrance"/>
  <property name="model"/>
  <component name="address">
   <property name="street"/>
   <property name="province"/>
   <property name="number"/>
   <property name="country"/>
   <property name="city"/>
   <property name="cap"/>
  </component>
  <many-to-one name="society">
   <column name="society"/>
  </many-to-one>
  <many-to-one name="zone">
   <column name="zone"/>
  </many-to-one>
  <property name="buildingAdmin"/>
  <property name="buildingAdminPhone"/>
  <property name="contractExpiringDate"/>
  <property name="keyholder"/>
  <property name="keyholderPhone"/>
  <property name="responsable"/>
  <property name="responsablePhone"/>
  <property name="state"/>
  <many-to-one name="category"/>
</class>


Code :
Code:
Criterion expression = Expression.ilike(constraint.getProperty().getSubField(),constraint.getProperty().getValue());
                     if(constraint.getOperator() == Constraint.notILIKE){
                        expression = Expression.not(expression);
                     }
                     criteria.createCriteria(constraint.getProperty().getField()).add(expression);
                     criteriaTotalCounter.createCriteria(constraint.getProperty().getField()).add(expression);
...
         criteriaTotalCounter.setProjection(Projections.rowCount());
//I get Exception here :
         Object rowCount = criteriaTotalCounter.list().get(0);

Name and version of the database you are using:

Postgres 8.0.3


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.