Fórum

Joining portal tables with portlet tables using Hibernate - impossible?

thumbnail
Tomas Polesovsky, modificado 14 Anos atrás.

Joining portal tables with portlet tables using Hibernate - impossible?

Liferay Master Postagens: 676 Data de Entrada: 13/02/09 Postagens Recentes
Hi,

I need to join ExpandoValue entity with my entity Lead, that I've created using ServiceBuilder.

But I got very unpretty error emoticon

Caused by: org.hibernate.MappingException: Unknown entity: com.liferay.portlet.expando.model.impl.ExpandoValueImpl
	at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:580)
	at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:69)
	at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:357)
	at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:102)
	at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
	at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:91)
	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1577)
	at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
	at com.liferay.portal.dao.orm.hibernate.DynamicQueryImpl.list(DynamicQueryImpl.java:95)
	at com.liferay.portal.dao.orm.hibernate.DynamicQueryImpl.list(DynamicQueryImpl.java:91)
	... 158 more
</init></init></init>


The code is here:

        DynamicQuery query = DynamicQueryFactoryUtil.forClass(Lead.class);

        DynamicQuery expandoSearchQuery = DynamicQueryFactoryUtil.forClass(ExpandoValue.class, "searchColumn", PortalClassLoaderUtil.getClassLoader());
        expandoSearchQuery.setProjection(
                ProjectionFactoryUtil.projectionList()
                .add(ProjectionFactoryUtil.property("searchColumn.classPK")));
        expandoSearchQuery
                .add(RestrictionsFactoryUtil.eq("searchColumn.columnId", searchColumn.getColumnId()))
                .add(RestrictionsFactoryUtil.eq("searchColumn.data_", "%" + filter.getSearchData()+"%"));
        // join on searchQuery
        query
            .add(PropertyFactoryUtil.forName(LeadConstants.Column.ID.header()).in(expandoSearchQuery));


As I understand it, my portlet's hibernate session factory (using PortletHibernateConfiguration) doesn't know definition of entity ExpandoValueImpl, which is in portal's hibernate session factory (using PortalHibernateConfiguration).

In fact it means that I can't join any of portal tables together with portlet table and vice versa. Is it correct?
thumbnail
Tomas Polesovsky, modificado 13 Anos atrás.

RE: Joining portal tables with portlet tables using Hibernate - impossible?

Liferay Master Postagens: 676 Data de Entrada: 13/02/09 Postagens Recentes
Created ticket LPS-8292

-- tom
Francisco Aranda, modificado 13 Anos atrás.

RE: Joining portal tables with portlet tables using Hibernate - impossible?

New Member Postagens: 6 Data de Entrada: 24/05/10 Postagens Recentes
Hi!, could you find a solution for this? I'm having the same problem. I need to search by expando columns in my custom spring portlet.
Thanks!
Francisco Aranda, modificado 13 Anos atrás.

RE: Joining portal tables with portlet tables using Hibernate - impossible?

New Member Postagens: 6 Data de Entrada: 24/05/10 Postagens Recentes
Ok, I found the solution adding the portalClassLoader parameter to DynamicQueryFactoryUtil.forClass Method.

If anyone else is having the same problem, here is my working example of how I'm searching for BlogsEntries having an expando column called "featured" with value "true".



List<blogsentry> blogEntries = new ArrayList<blogsentry>();

try{
ExpandoColumn column = ExpandoColumnLocalServiceUtil.getDefaultTableColumn(
    themeDisplay.getCompanyId(), BlogsEntry.class.getName(),
    "featured");
if (column != null) {

    ClassLoader cl = PortalClassLoaderUtil.getClassLoader();

    DynamicQuery query = DynamicQueryFactoryUtil.forClass(
        ExpandoValue.class,cl);

    query.add(RestrictionsFactoryUtil.eq(
        "tableId", column.getTableId()));
    query.add(RestrictionsFactoryUtil.eq(
        "columnId", column.getColumnId()));
    query.add(RestrictionsFactoryUtil.ilike(
        "data", "%true%"));

    List<expandovalue> results = ExpandoValueLocalServiceUtil.dynamicQuery(query);

      for (ExpandoValue expandoValue : results) {
	BlogsEntry entry = BlogsEntryLocalServiceUtil.getBlogsEntry(expandoValue.getClassPK());
    
        blogEntries.add(entry);
 }


}



</expandovalue></blogsentry></blogsentry>
thumbnail
Tomas Polesovsky, modificado 13 Anos atrás.

RE: Joining portal tables with portlet tables using Hibernate - impossible?

Liferay Master Postagens: 676 Data de Entrada: 13/02/09 Postagens Recentes
Hello Francisco,

I'm sorry but this is not the same case emoticon

You can of course search in portal table using portal classloader, but you are unable to join portal and portlet tables.

-- tom
thumbnail
Aritz Galdos, modificado 13 Anos atrás.

RE: Joining portal tables with portlet tables using Hibernate - impossible?

Expert Postagens: 416 Data de Entrada: 15/05/07 Postagens Recentes
Facing the same problem one year later emoticon

Any solution so far?

Regards
thumbnail
Tomas Polesovsky, modificado 13 Anos atrás.

RE: Joining portal tables with portlet tables using Hibernate - impossible?

Liferay Master Postagens: 676 Data de Entrada: 13/02/09 Postagens Recentes
Hi,

1, join tables in memory
or
2, use native sql
or
3, for every entity you want to join (from different session) create definition in your hibernate config file (e.g. if you want to join User entity from portal, create your definition of user in your portlet app in portlet-hbm.xml and create your new User class)

Don't forget to clean Liferay and Hibernate L2 caches when updating!

-- tom