RE: Interface Error CustomSQL

Amos Fong, modified 6 Years ago. Junior Member Posts: 25 Join Date: 3/14/19 Recent Posts
Hi,

I followed this and got a weird error, i din't found it anywhere before :

2019-03-15 08:52:20.145 ERROR [http-nio-8080-exec-8][JSONWebServiceServiceAction:116] Found interface com.liferay.portal.dao.orm.custom.sql.CustomSQL, but class was expected

I tried all i found about CustomSQL on the net, when i replace CustomSQL with CustomSQLUtil i have an error returning : 
​​​​​​​
2019-03-15 08:50:31.324 ERROR [http-nio-8080-exec-4][JSONWebServiceServiceAction:116] com/liferay/portal/dao/orm/custom/sql/CustomSQLUtil

I realy don't know what to do, the package is in my dependencies' folder, i can open the CustomSQL* classes but i can't use any of their methods

Help ! 

here is the part of my code wich don't work : 

    public static final String FIND_BY_ROLES_ID_AND_PORTLET_ID_AND_ENTITY =
            PermissionFinder.class.getName() +
                ".findByRolesIdAndPortletIdAndEntity";

    @ServiceReference(type=CustomSQL.class)
    private CustomSQL _customSQL;
    
    public List<Permission> findByRolesIdAndPortletIdAndEntity(long[] roleIds, String portletId, String entity){
        Session session = null;
        try {
            session = openSession();
            
            //System.out.println(CustomSQLUtil.class);
            String sql = _customSQL.get(getClass(), FIND_BY_ROLES_ID_AND_PORTLET_ID_AND_ENTITY);
            System.out.println("La Requete : "+sql);
            SQLQuery q = session.createSQLQuery(sql);
            q.setCacheable(false);
            q.addEntity("agiirpermission", PermissionImpl.class);
            System.out.println("La SQL Query : "+q);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(roleIds);
            qPos.add(portletId);
            qPos.add(entity);
            return (List<Permission>) QueryUtil.list(q, getDialect(), 0, 0);
        }
        catch (Exception e) {
            try {
                throw new SystemException(e);
            }
            catch (SystemException se) {
                se.printStackTrace();
            }
        }
        finally {
            closeSession(session);
        }
        return new ArrayList<Permission>();
    }
 
thumbnail
Amos Fong, modified 6 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
This works for me:

import com.liferay.portal.dao.orm.custom.sql.CustomSQLUtil;
...

CustomSQLUtil.get(getClass(), "xxx")

and my bnd:
compileOnly group: "com.liferay", name: "com.liferay.portal.dao.orm.custom.sql", version: "1.0.0"

What's the full stacktrace when you try that?
Dorian Penot, modified 6 Years ago. Junior Member Posts: 25 Join Date: 3/14/19 Recent Posts
When I use CustomSqlUtil the error is worst, just give me this : 

2019-03-20 08:29:23.791 ERROR [http-nio-8080-exec-2][JSONWebServiceServiceAction:116] com/liferay/portal/dao/orm/custom/sql/CustomSQLUtil
I don't have anything else and it don't work neither. I changed my dependencie like yours but still the same. 

I realy don't understand what i did wrong 
Dorian Penot, modified 6 Years ago. Junior Member Posts: 25 Join Date: 3/14/19 Recent Posts
Ok i changed the import like this : 

    compileInclude group: "com.liferay", name: "com.liferay.portal.dao.orm.custom.sql", version: "1.0.0"
So i would say that if I import 1.0.3 it don't work for me but 1.0.0 work ? that's realy weird but thank you for your help ! 
thumbnail
Amos Fong, modified 6 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
That's strange, maybe your runtime environment doesn't have 1.0.3? Anyway, glad it's working now emoticon
thumbnail
Amos Fong, modified 6 Years ago. Liferay Legend Posts: 2047 Join Date: 10/7/08 Recent Posts
FYI, just ran into this error on 7.1 which was caused by a wrong module import name:

good:
    compileOnly group: "com.liferay", name: "com.liferay.portal.dao.orm.custom.sql.api", version: "1.0.0"

bad:
    compileOnly group: "com.liferay", name: "com.liferay.portal.dao.orm.custom.sql", version: "1.0.0"
Dorian Penot, modified 6 Years ago. Junior Member Posts: 25 Join Date: 3/14/19 Recent Posts
I don't know because for me thi worked : 

compileOnly group: "com.liferay", name: "com.liferay.portal.dao.orm.custom.sql", version: "1.0.0"

But this didn't worked :

​​​​​​​compileOnly group: "com.liferay", name: "com.liferay.portal.dao.orm.custom.sql", version: "1.0.3"
​​​​​​​I have no idea where it come from, i didn't tried with sql.api ...