Link to home
Start Free TrialLog in
Avatar of icylin
icylin

asked on

org.hibernate.TypeMismatchException

Hello,

I am getting the following
org.hibernate.TypeMismatchException: left and right hand sides of a binary logic operator were incompatibile[partyId, String]

I am trying to query database using following hql query shown below. mappings for the files are shown below.

Am i doing something wrong here?
Please help me out with this hql query.

Thanks.
String queryString="select depot from DepotAlias as depot where depot.name like '%FRE%'and id.party.id=:partyId";
Query query = session.createQuery(queryString);
query.setParameter(partyId,"FREON")

Open in new window

<class name="DepotAlias" table="depot_alias" mutable="false" batch-size="250">
 
            <composite-id class="DepotAliasKey" name="id">
                  <key-many-to-one name="party" column="party_ref" />
                  <key-property name="id" column="depot_alias" type="trim" />
            </composite-id>
 
            <property name="name" column="depot_alias_desc" type="trim" />
             ......

</class>

Open in new window

<hibernate-mapping>
  <class name="Party" table="party_tbl">
    <id name="id" column="party_ref" type="string">
      <generator class="assigned"/>
    </id>
    ....
</class>

Open in new window

Avatar of for_yan
for_yan
Flag of United States of America image

maybe you are msising the space ebfore the "and" in the query :  ...  '%FRE%'(right here you neeed space)and id....

Also two dots here "id.party.id" look a little bits starnge - please check.
Avatar of Gurvinder Pal Singh
Is your partyId an integer or a String? please cross check the same
Avatar of icylin
icylin

ASKER

There is a space '%FRE%'.. my typing mistake. Also partyId is a string.
Actual query goes something like this:
"select depot from DepotAlias as depot where depot.name like '%FRE% 'and depot.id.party.id=:partyId"
Avatar of icylin

ASKER

Sorry its actually
"select depot from DepotAlias as depot where depot.name like '%FRE% and depot.id.party.id=:partyId"

Now you don't have second single quote after %

Maybe you can post soem of your class definitions?





Hi there,
i do suspect there is a space required '%FRE%'and  & is it PartyID or party.id only. then why you want to have multiple dots in there?.

Please verify once. good luck
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of icylin

ASKER

basically what i am trying to get is trying to write a select query in hql

select sql query that i wanted to write was:
select * from depot_alias where name like '%FRE%' and party_ref='FOO_REF'


<class name="Party" table="party_tbl" mutable="false" batch-size="250">

		<id name="id" column="party_ref" type="trim">
			<generator class="assigned" />
		</id>

		<property name="name" column="party_short_name_p2k" type="trim"/>
		</class>

Open in new window

<class name="DepotAlias" table="depot_alias_wil" mutable="false"
		batch-size="250">

		<composite-id class="DepotAliasKey" name="id">
			<key-many-to-one name="party" column="party_ref" />
			<key-property name="id" column="depot_alias" type="trim" />
		</composite-id>

		<property name="name" column="depot_alias_desc" type="trim" />
		</class>

Open in new window

public class DepotAlias {
		private DepotAliasKey id;
		private String name;
		//constructors with getters and setters.
		}
		
		public class DepotAliasKey{

	protected Party party;
	protected String id;
	//constructors with getters and setters.
	}
	
	public class Party{
	protected String id;
	//constructors with getters and setters.
	}

Open in new window

StringBuffer queryString= new StringBuffer("select distinct depotAlias from DepotAlias as depotAlias where (depotAlias.name like '%FRE%''));
		if(filter.getParty()!=null)
		{
			queryString.append(" and depotAlias.id.party.id= :partyIdentifier");
		}
		
		query = getSession().createQuery(queryString.toString());
		query.setParameter("partyIdentifier", filter.getParty().getDataId()); //filter.getParty().getDataId() returns string
		List<DepotAlias> result = (List<DepotAlias>) query.list();

Open in new window

Avatar of icylin

ASKER

Do we need to have a join to achive above sql query  in HQL?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial