on ‎2018 Nov 05 10:47 AM
Hello all ,
I have made a many - many relation between two tables , first table is Showrooms the other one is Plants and the Joining table is ShowroomPlantRelation , my aim is to get list of plants by a showroom code ,, i have wrote this flexible search query
SELECT {p:plantCode} FROM { Plants as p JOIN ShowroomPlantRelation as rel ON {p:PK} = {rel:target} JOIN Showrooms AS S ON {rel:source} = {S:PK} } WHERE {S.showRoomCode}=0000
and it has worked in HAC flexible search and give me the correct results 'p1' , but when i embed it into the code it gives me this exception java.sql.SQLException: Invalid value for getLong() - 'p1'
my java code is :-
**public List<PlantsModel> findPlantsByShowRoomCode(final String showRoomCode)
{
final String queryString = "SELECT {p:plantCode} FROM {Plants as p JOIN ShowroomPlantRelation as rel ON {p:PK} = {rel:target}JOIN Showrooms AS S ON {rel:source} = {S:PK}}WHERE {S.showRoomCode}= " + "?showRoomCode ";
final FlexibleSearchQuery query = new FlexibleSearchQuery(queryString);
query.addQueryParameter("showRoomCode", showRoomCode);
return flexibleSearchService.<PlantsModel> search(query).getResult();
}**
what i am missing here that makes my flexible search query doesn't work in my code ?
Request clarification before answering.
You should return PKs in your search:
`SELECT {p:PK} FROM { Plants as p JOIN ShowroomPlantRelation as rel ON {p:PK} = {rel:target} JOIN Showrooms AS S ON {rel:source} = {S:PK} } WHERE {S.showRoomCode}=0000`
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you , I have solved the issue by changing the flexible search query into :-
final String queryString = // "SELECT {p:" + PlantsModel.PK + "}" + "FROM {" + PlantsModel._TYPECODE + " AS p JOIN ShowroomPlantRelation as rel ON {p:PK} = {rel:target}JOIN Showrooms AS S ON {rel:source} = {S:PK}}"// + "WHERE " + "{S.showRoomCode}=" + "?showRoomCode ";
Hi Prihan,
In the flexible search you select codes (String) but you put as result class PlantsModel.
you must specify String as result class then return the result.
query.setResultClassList(Arrays.asList(String.class));
final SearchResult<String> result = getFlexibleSearchService().search(query);
return result.getResult();
Best regards,
Anouar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.