RE: Query by joining two tables from different scope

Ronak Parekh, 5 Jaren geleden aangepast. New Member Berichten: 10 Aanmelddatum: 5-11-20 Recente berichten

Hello Team,

I want to query by joining two tables: one is portal level entity and another one is custom entity i.e JournalArticle and ArticleUserMapping entity. Please suggest how can I query by joining these two tables. I have tried using Dynamic Query but in Liferay 7.2 I am not able to create dynamic query with alias and I think without alias I won't able to query as per my requirement.

How can I use custom sql? How can I write custom sql of journal article entity joined with custom entity in custom entity's finder impl

Kindly help.

Thank you. 

thumbnail
Christoph Rabel, 5 Jaren geleden aangepast. Liferay Legend Berichten: 1555 Aanmelddatum: 24-9-09 Recente berichten

Here's the documentation for custom sql. I hope, it helps.

https://help.liferay.com/hc/en-us/articles/360017882012-Custom-SQL

When you write the code, you can add an Impl class that matches the table, in that example EntryImpl is used.

q.addEntity("GB_Entry", EntryImpl.class);

What I did before is was to add my own class that matched the result. I used the "dummy entity trick" by Dave Nebinger. It should still work.

https://liferay.dev/blogs/-/blogs/fake-servicebuilder-entities

But I think, doing that isn't strictly necessary, I think, any class works, as long as the column names match the setters/getters. But I could be wrong here.

thumbnail
Andrew Jardine, 5 Jaren geleden aangepast. Liferay Legend Berichten: 2416 Aanmelddatum: 22-12-10 Recente berichten

.. The only thing I would add here is that the dummy entities got a little bit cleaner in 7.2 because you can now generate service builder entities without the persistence layer. So that means you don't have to worry about "disabling" the crud operations. All you have to do is make sure that you set the attribute persistence="false" on the <entity/> definition and Service Builder will do the rest .. or rather do LESS for you :)