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

icylinAsked:
Who is Participating?
 
for_yanCommented:

@Plk_In_EE,
But the Asker says he actually did have space - just here posted incorrectly - look above : ID:36940542Author
0
 
for_yanCommented:
maybe you are msising the space ebfore the "and" in the query :  ...  '%FRE%'(right here you neeed space)and id....
0
 
for_yanCommented:

Also two dots here "id.party.id" look a little bits starnge - please check.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Gurvinder Pal SinghCommented:
Is your partyId an integer or a String? please cross check the same
0
 
icylinAuthor Commented:
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"
0
 
icylinAuthor Commented:
Sorry its actually
"select depot from DepotAlias as depot where depot.name like '%FRE% and depot.id.party.id=:partyId"
0
 
for_yanCommented:

Now you don't have second single quote after %

Maybe you can post soem of your class definitions?





0
 
Plk_In_EECommented:
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
0
 
icylinAuthor Commented:
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

0
 
icylinAuthor Commented:
Do we need to have a join to achive above sql query  in HQL?
0
 
Gurvinder Pal SinghCommented:
did you cross checked the data type of party.id?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.