Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:2.1.7
Mapping documents:
<class name="CodedRecordImpl" table="business_directory_coded">
<id name="Id" type="int" column="ID">
<generator class="assigned"/>
</id>
<property name="company_name" column="company_name" type="string" length="50"/>
<property name="address1" column="address1" type="string" length="150"/>
<property name="address2" column="address2" type="string" length="150"/>
<property name="address3" column="address3" type="string" length="150"/>
<property name="town" column="town" type="string" length="50"/>
<property name="county" column="county" type="string" length="50"/>
<property name="postcode" column="postcode" type="string" length="10"/>
<property name="web" column="web" type="string" length="150"/>
<property name="telephone" column="telephone" type="string" length="15"/>
<property name="postsect" column="postsect" type="string" length="10"/>
<property name="postdist" column="postdist" type="string" length="5"/>
<property name="postarea" column="postarea" type="string" length="2"/>
<property name="la_2002" column="la_2002" type="string" length="50"/>
<property name="CTPS" column="CTPS" type="char"/>
<property name="TPS" column="TPS" type="char"/>
<property name="FPS" column="FPS" type="char"/>
<property name="MPS" column="MPS" type="char"/>
<many-to-one name="primaryDescriptionDetails" class="PrimaryDescriptionImpl" column="sic_primary_code"/>
<many-to-one name="secondaryDescriptionDetails" class="SecondaryDescriptionImpl" column="sic_secondary_code"/>
<many-to-one name="tertiaryDescriptionDetails" class="TertiaryDescriptionImpl" column="sic_tertiary_code"/>
<many-to-one name="thomsonDescriptionDetails" class="ThomsonDescriptionImpl" column="thomson_code"/>
<many-to-one name="ward2004Details" class="Ward2004Impl" column="ward_2004"/>
</class>
<class name="PrimaryDescriptionImpl" table="1992_sic_primary_level1_description" lazy="true">
<id name="primary_code" type="char" column="primary_code">
<generator class="assigned"/>
</id>
<property name="primary_description" column="primary_description" type="string" length="150" />
</class>
<class name="SecondaryDescriptionImpl" table="1992_sic_secondary_description" lazy="true">
<id name="secondary_code" type="string" column="secondary_code">
<generator class="assigned"/>
</id>
<property name="secondary_description" column="secondary_description" type="string" length="150"/>
</class>
<class name="TertiaryDescriptionImpl" table="1992_sic_tertiary_description" lazy="true">
<id name="tertiary_code" type="string" column="tertiary_code">
<generator class="assigned"/>
</id>
<property name="tertiary_description" column="tertiary_description" type="string" length="150"/>
</class>
<class name="ThomsonDescriptionImpl" table="lu_thomson" lazy="true">
<id name="thomson_code" type="string" column="thomson_code">
<generator class="assigned"/>
</id>
<property name="thomson_description" column="thomson_description" type="string" length="150"/>
</class>
<class name="Ward2004Impl" table="lu_ward_2004" lazy="true">
<id name="ward_2004" type="string" column="ward_2004">
<generator class="assigned"/>
</id>
<property name="ward_2004_name" column="ward_2004_name" type="string" length="50"/>
<property name="la_2002" column="la_2002" type="string" length="50"/>
</class>
<query name="codedrecord.checkprimary">from PrimaryDescriptionImpl where primary_code = ?</query>
<query name="codedrecord.checksecondary">from SecondaryDescriptionImpl where secondary_code = ?</query>
<query name="codedrecord.checktertiary">from TertiaryDescriptionImpl where tertiary_code = ?</query>
<query name="codedrecord.checkthomson">from ThomsonDescriptionImpl where thomson_code = ?</query>
<query name="codedrecord.checkward">from Ward2004Impl where ward_2004 = ?</query>
<query name="codedrecord.clear">delete from CodedRecordImpl</query>
<query name="codedrecord.search.companyname">from CodedRecordImpl where company_name like ?</query>
<query name="codedrecord.search.pcode">from CodedRecordImpl where sic_primary_code like ?</query>
<query name="codedrecord.search.ward">from CodedRecordImpl where ward_2004 like ?</query>
<query name="primarydescription.getall">from PrimaryDescriptionImpl order by primary_description</query>
<query name="ward.getall">from Ward2004Impl order by ward_2004_name</query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session ses=super.getSession();
Criteria crit= ses.createCriteria(CodedRecord.class);
if(titleSearch!=null)crit.add( Expression.like("company_name",titleSearch ) );
if(addressSearch!=null)crit.add( Expression.like( "address1", "%"+addressSearch+"%" ) );
if(addressSearch!=null)crit.add( Expression.like( "address2", "%"+addressSearch+"%" ) );
if(addressSearch!=null)crit.add( Expression.like( "address3", "%"+addressSearch+"%" ) );
if(wardSearch!=null)crit.add( Expression.like( "ward_2004", wardSearch ) );
if(primarySearch!=null)crit.add( Expression.like( "sic_primary_code", primarySearch ) );
crit.addOrder( Order.asc("company_name"));
crit.setMaxResults(1000);
ArrayList al =(ArrayList) crit.list();
Full stack trace of any exception that occurs:
net.sf.hibernate.QueryException: could not resolve property: sic_primary_code of: com.scientia.busdir.beans.CodedRecordImpl
at net.sf.hibernate.persister.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:50)
at net.sf.hibernate.expression.AbstractCriterion.getColumns(AbstractCriterion.java:42)
at net.sf.hibernate.expression.SimpleExpression.toSqlString(SimpleExpression.java:40)
at net.sf.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:64)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3630)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at com.scientia.dao.hibernate.CodedRecordDAOImpl.AdvancedSearch(CodedRecordDAOImpl.java:107)
The search works fine when i preform it on the fields of CodedRecordImpl, but when i try to search on one of the fields that relates to a relationship i get the above problem...what i am i going wroung?