留言板

Unable to import CustomSQLUtil in liferay 7

Thirumal Reddy,修改在7 年前。

Unable to import CustomSQLUtil in liferay 7

Regular Member 帖子: 216 加入日期: 15-12-3 最近的帖子
Hi All,
while implementing finderImpl for custom-sql, i am unable import a file
"com.liferay.util.dao.orm.CustomSQLUtil"
why it is not importing.?
any suggestions.?

regards,
Thirumal.
thumbnail
David H Nebinger,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
The only answer that comes to mind is that you didn't configure your project correctly, if at all.

That's just an off the cuff answer, of course, because there's no details about what version of Liferay you're using, what your build environment is (sdk, maven, gradle), etc.

Is there an error for the import or something? Or just an indicator from the IDE that it can't find it? Does a build work, pointing to a fine build environment just an unclear classpath definition for the IDE?

More details will help identify what is going on and provide a better response...






Come meet me at the LSNA!
Thirumal Reddy,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Regular Member 帖子: 216 加入日期: 15-12-3 最近的帖子
Hi
I am using,
JDK-1.8
MySql-5.6
Liferay 7 GA2 with gradle build environment.
I have developed a portlet with plugins SDK, where i am not getting any problem with "CustomSQLUtil" in finderImpl classes.
but while devolping a servicebuilder module project.,
in that while implementing finderImpl class, i am unable import "com.liferay.util.dao.orm.Custom**" package
and it is saying error "The import com.liferay.util cannot be resolved".
to resolve i have configured project build path by adding "util-java.jar." it resolved error in editor, but while deploying project i am getting exception with CustomSQLUtil .

regards,
Thirumal.
thumbnail
Jamie Sammons,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Expert 帖子: 301 加入日期: 14-9-5 最近的帖子
Hello,

Make sure you have an entry in your build.grade file that pulls in util-java as a dependency:

compile ‘com.liferay:com.liferay.portal.dao.orm.custom.sql:1.0.3’

Hope that helps.

Update: I added the wrong module entry. It has been corrected.
Thirumal Reddy,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Regular Member 帖子: 216 加入日期: 15-12-3 最近的帖子
Hi Jamie Sammons
as per this custom-sql,
we need to import this " com.liferay.util.dao.orm.CustomSQLUtil" and need to call
" String sql = CustomSQLUtil.get( FIND_BY_ENTRYNAME_ENTRYMESSAGE_GUESBOOKNAME);"
but after adding this "compile ‘com.liferay:com.liferay.portal.dao.orm.custom.sql:1.0.3’", dependency
i am unable to call directly "get( FIND_BY_ENTRYNAME_ENTRYMESSAGE_GUESBOOKNAME)",
it asking to call "get(Class<?> clazz, String id)"
so how to resolve this conflict.
please help me.

regards,
Thirumal.
thumbnail
Jamie Sammons,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Expert 帖子: 301 加入日期: 14-9-5 最近的帖子
Hi Thirumal,

The method now requires you to pass in your current class. Try changing your code to something like:

String sql = CustomSQLUtil.get(MyClass.class, FIND_BY_ENTRYNAME_ENTRYMESSAGE_GUESBOOKNAME); 

-Jamie
Thirumal Reddy,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Regular Member 帖子: 216 加入日期: 15-12-3 最近的帖子
Hi,
Thanks Jamie Sammons.
i have modified my code to like this ,
CustomSQLUtil.get(Book.class, FIND_BY_ENTRYNAME_ENTRYMESSAGE_GUESBOOKNAME);

It's working, but *FinderUtil is not generating.
I have done so many times build service, deploy and gradle refresh but it didn't generated.
please take me out from this probemoticon

regards,
Thirumal.
thumbnail
David H Nebinger,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
I don't understand what you mean that it is not generating?





Come meet me at the LSNA!
Thirumal Reddy,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Regular Member 帖子: 216 加入日期: 15-12-3 最近的帖子
Hi David,
*FinderUtil interface is not generating after adding method in *FinderImpl class.
after adding method i did build service and gradle refresh even though the *FinderUtil interface is not generating.
so i am unable to implement those methods in *LocalServiceImpl.

regards,
Thirumal.
thumbnail
David H Nebinger,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Well, honestly it's hard to say. The finder class has to be named correctly, has to be in the appropriate directory, has to have the appropriate visibility, services have to be rebuilt successfully, ...

Through this forum post we really can't get much visibility into many of these. Can you share the project via github or post a zip here?







Come meet me at the LSNA!
Thirumal Reddy,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Regular Member 帖子: 216 加入日期: 15-12-3 最近的帖子
Hi Daivd,
Thanks for you'r support.
here i am attaching my zip file please verify it.

regards,
Thirumal.
thumbnail
David H Nebinger,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
I see now what you mean about the missing Util class, but honestly they're kinda deprecated at this point. You really should be considering using full-on OSGi service injection rather than using the Util classes anyway.

That said, I'll see if I can find anything...






Come meet me at the LSNA!
Thirumal Reddy,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Regular Member 帖子: 216 加入日期: 15-12-3 最近的帖子
Hi David,
any sol'n regarding XXXFinderUtil.
i am waiting for your replay.

regards,
Thirumal.
Thirumal Reddy,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Regular Member 帖子: 216 加入日期: 15-12-3 最近的帖子
Hi David,
any sol'n regarding XXXFinderUtil.
i am waiting for your replay.
@Jamie Sammons, suggestion is not working.
regards,
Thirumal.
thumbnail
David H Nebinger,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Even if it is a bug, it's not going to be solved any time soon, especially if it hasn't been reported.

As I see it you have two options:

1. Go full-on OSGi and use either a ServiceTracker or a ServiceReference annotation to get the finder injected in a true OSGi fashion.
2. The XxxLocalServiceImpl may have an instance available in it, so you could add methods to proxy calls to the finder. The proxy methods you add there would make it into XxxLocalServiceUtil.

But again I must emphasize that option #2 is not the recommended way to do this. The util classes, at this point, are supposed to be used in cases where OSGi injection simply isn't possible. For all normal types of implementations, option #1 is the recommended way.






Come meet me at the LSNA!
Thirumal Reddy,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Regular Member 帖子: 216 加入日期: 15-12-3 最近的帖子
Hi David,
Thanks for your response.
I am new to OSGI technology., i don't know about how to use ServiceTracker / ServiceReference annotations
so could you please provide one demo project or any links related to this.

regards,
Thirumal.
thumbnail
Jamie Sammons,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Expert 帖子: 301 加入日期: 14-9-5 最近的帖子
Hi Thirumal,

You shouldn't have to worry about injecting it because its already done for you by Service Builder in the bottom of BookLocalServiceBaseImpl with the line:

@BeanReference(type = BookFinder.class)
protected BookFinder bookFinder;


I’m attaching a working copy of the sample you provided. Please take a look and let me know if you run into any issues.

-Jamie
thumbnail
Jamie Sammons,修改在7 年前。

RE: Unable to import CustomSQLUtil in liferay 7

Expert 帖子: 301 加入日期: 14-9-5 最近的帖子
I think all you should have to do is change BookFinderUtil.findBooks("%" + bookTitle + "%"); to bookFinder.findBooks("%" + bookTitle + "%");

Hope that helps.
Chad LaVigne,修改在6 年前。

RE: Unable to import CustomSQLUtil in liferay 7

New Member 帖子: 10 加入日期: 13-11-12 最近的帖子
Jamie, thanks for posting this, it's very helpful. I spent a lot of time reading the documentation and other posts trying to figure out how to include the util-java dependencies in a service builder project. Everything else I found said util-java wasn't osgi friendly and I'd have to include it in my module which had me going down the painful path of trying resolve all the transitive dependencies manually. When I'm trying to solve problems like this in the future, how do I find the correct dependency references to put in the Gradle file? For example, when I get missing dependency messages in the gogo shell, it's fairly easy to figure out what jar file contains the classes I need, but how do I figure out
compile 'com.liferay:com.liferay.portal.dao.orm.custom.sql:1.0.3'
is what I need in my Gradle file to include util-java.jar and it's dependencies?