• Concept of ClassPK in liferay

    Posted on May 27, 2015 by Hamidul Islam in Liferay.


    aimClassPK in Liferay can be confusing if its not understood properly. Along with classPK in liferay there is another term called classNameId which are commonly used. This article explains the nut and bolts of classPK in Liferay. We will also explain how to analyze Liferay Tables where classPKs are used as a column name. 

    Fact 1: 

    Every Entity generated by Liferay Service Builder Tool has its unique ID which is called classNameId. Consider that we have our custom portlet where we have used Service Builder Tool to generate code. So when the portlet is deployed for the first time the name of the Entity will be registered in a table and classNameId will be also generated. Below is the table (i.e., classname_) where all the registered Entity's  are persisted. 



    Some rows of classname_ table:


    The classNameId as well as value are unique in the classname_ table. Even combining classNameId and value column the record is always unique in classname_ table.

    Fact 2: 

    There are many tables in liferay default database lportal. We can see classPK as column name in some of those tables. So what should we interpret by looking classPK as column name?

    In simple classPK represents primary keys of a records which are in different table. That means classPK just like a foreign key reference. 

    Fact 3: 

    We understood by Fact 2 mentioned in above that classPKs are just like a foreign key reference to some other table. So how would we know table name for which we have the classPK. In other words by classPK how would I find corresponding record in other table.

    The answer is simple. The tables where classPK column is available, classNameId would be also available in the same table. By classNameId we can give a look up in classname_ table to find out corresponding entity name. If we know the entity name then we can easily find out table name associated with the entity name.   


    Try assetentry table of liferay and follow the below strategy.  


    Liferay Service for classname_ table:

    Some code 

    ClassName className = ClassNameLocalServiceUtil.getClassName("com.liferay.portlet.expando.model.ExpandoRow");
    ClassName classNamee = ClassNameLocalServiceUtil.getClassName(10107);
    long classNameId = ClassNameLocalServiceUtil.getClassNameId("com.liferay.portlet.expando.model.ExpandoRow");





    Post Tagged with , , ,

3 Responses so far.

  1. Tobias says:


    nice explanation. I nedded much time to understand this on my own. 🙂
    Maybe you also know a probability to add new className_ entries via a config file like portal-ext.properties or portlet.xml to add some portlet specific classNames?

    A programatical way is fine too but I think I can figure this out in my own.



  2. Aravinth says:

    It helped me to understand classpk and classnameid easily.Great work.


  3. renu says:

    nice explanation.. thanks

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.