icylin
asked on
org.hibernate.TypeMismatchException
Hello,
I am getting the following
org.hibernate.TypeMismatch Exception: 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.
I am getting the following
org.hibernate.TypeMismatch
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")
<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>
<hibernate-mapping>
<class name="Party" table="party_tbl">
<id name="id" column="party_ref" type="string">
<generator class="assigned"/>
</id>
....
</class>
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.
Is your partyId an integer or a String? please cross check the same
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 "
Actual query goes something like this:
"select depot from DepotAlias as depot where depot.name like '%FRE% 'and depot.id.party.id=:partyId
ASKER
Sorry its actually
"select depot from DepotAlias as depot where depot.name like '%FRE% and depot.id.party.id=:partyId "
"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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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'
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>
<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>
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.
}
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();
ASKER
Do we need to have a join to achive above sql query in HQL?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.