Message Boards

Cutom Finder to search in a table from another module

thumbnail
Nader Jafari, modified 4 Years ago.

Cutom Finder to search in a table from another module

Junior Member Posts: 84 Join Date: 8/24/11 Recent Posts
Hi folks
I have confused with custom sql in liferay 7.1

for simple Query like this :
CPInstance : is an entity in another module
CPLicense : is an entity in my module


            SELECT
                DISTINCT CPInstance.*
            FROM
                CPInstance
            INNER JOIN
                CPLicense ON
                    CPLicense.cpInstanceId = CPInstance.cpInstanceId


i created an finderImpl in my module and my problem is here :


            String sql = _customSQL.get(getClass(), FIND_BY_G_O);
            SQLQuery q = session.createSynchronizedSQLQuery(sql);
            q.addEntity(CPInstanceImpl.TABLE_NAME, CPInstanceImpl.class);
            QueryPos qPos = QueryPos.getInstance(q);
            return  QueryUtil.list(
            q, getDialect(), start, end);


I dont access to CPInstanceImpl that exist in antoher module
How can i run this Query and cast the results to CPInstanceImpl in my module?
thumbnail
Amos Fong, modified 4 Years ago.

RE: Cutom Finder to search in a table from another module

Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
You could make the finder in your CPInstance module and make it available to the CPLicense module via the LocalService. I don't think there's an easy way to get around the classloading issue.
thumbnail
saleem khan, modified 4 Years ago.

RE: Cutom Finder to search in a table from another module

Junior Member Posts: 71 Join Date: 11/16/13 Recent Posts
Hi,
The best thing you can do for this is to write the Custom SQL in the same module were your CPInstanceImpl exist. 

Another non recommended way is not to add entity to your SQLQuery and  use ModelMapper to map the object to model
thumbnail
Nader Jafari, modified 4 Years ago.

RE: Cutom Finder to search in a table from another module

Junior Member Posts: 84 Join Date: 8/24/11 Recent Posts
Hi friends
Thanks for your replies
I dont have access to CInstance module
It is a module in Liferay Commerce but i need this Entity to show in Search Container in my module.
What is the best practice to do this?
thumbnail
saleem khan, modified 4 Years ago.

RE: Cutom Finder to search in a table from another module

Junior Member Posts: 71 Join Date: 11/16/13 Recent Posts
Hi Nader,
I was thinking on this and was wondering why are you not using dynamic query for this. Because its going to save lot of time for you and faster than Custom SQL can you give more info on the query.For the Search container You can use  APIs . Include *.api.jar dependency and if you want *Impl include *.service.jar and you can get the access for all the service layer classes.
Hope I am understanding your problem correctly. Are having any problem with the APIs ?