Press "Enter" to skip to content

Database class mapping wizard in Pega

32

Introduction

In this post we will see how to use database class mapping wizard

Pega 7 introduced a separate database schema for rule and data.

  1. PegaRules – Contains rule tables.
  2. PegaData – Contains data instances like work item.

All the work and data tables resides in PegaData, whereas the rule tables reside in PegaRules.

Data can be organised in a data table as rows and columns.

We will see more of database in separate lesson.

Let’s jump into the topic.

All you  need to do is to create a table and map a class to that table.

Why do we need to map class to datatable?

  • We know Pega that stores the user session data in memory using clipboard pages, but we may need to persist the data for future reference.
  • Pega supports mapping class to the table, so that when we save a page of defined class, the particular instance gets saved to the mapped database table.
  • Remember only concrete classes can be mapped to dedicated database table.

Database commits are  handled by Pega platform.

As a developer all we need to do is,

  1. Create a new concrete class.
  2. Create a new table in DB.
  3. Map the class with the DB table.

First, let’s get to the basics.

What are the ways you can create a table in Pega?

We can see there are few ways by which Pega creates a new DB table without the help of DBA administrator.

1. While creating an application, you will see a work class and a class group (work pool) gets created and mapped to work table. A new work table is created in DB.

Step 1: Create a new application. Select PegaRules as built on application. Select two casetypes.

Step 2: After creating application Designer studio -> Data Model -> Classes & Properties -> database class mappings

You can see the Class mapped to database table.

XYZ-NewHire-Work mapped to pc_XYZ_NewHire_Work

2. Creating a new data type creates a new data table in DB.

Please go through the ‘Data type’ (http://myknowpega.com/2017/05/13/data-type-cascad…-control-example/) post to know how to create a new data type.

I created a Candidates data type. As soon as you configure, a local data storage a table gets created.

You can see Data type class – XYZ-Data-Candidates gets mapped to pr_XYZ_Data_Candidates.

3. Optimizing an aggregate property using optimization tool.

A new index table gets created. We will see more about this in separate lesson.

All the above three ways are implemented internally by Pega Platform.

How Pega handles?

There is an OOTB final rule in ‘Rule-Obj-Class’ – pzCreateTableForClass.

This is responsible for creating dedicated database table for particular classes.
What is Database class mapping wizard?

  • It is a mapping wizard, which creates a concrete class and maps to a particular DB table.

In simple words, you have a database table. Think, “How can we use that table in Pega?”.

Yes, you are going to map that table to a class. Map the columns to properties.

So saving a class instance implies making an entry to the table.

Prerequisites:

  • You need a separate DB table created in Database.
  • Required columns are available in the database table.

How do we use Database class mapping wizard?

Step 1: Move to Designer studio -> Data Model -> Classes & Properties -> database class mappings.

Step 2: Click on the ‘New External Database class mapping’.

You will see a modal dialog.Step 3: Specify the configurations.

Specify database table – Provide the DB name, schema, DB table name.

Specify ruleset class – Specify the ruleset details and a new Class name.

Map database columns to properties –

  • Key – You can check the column to make it as key to the table.
  • Property Name – You can select the properties in Key column and provide a Property Name in property column.
  • Map All/None – Creates new properties, if checked. Pega creates new properties in XYZ-PREM–Data-Countries class.

Here I have selected Country code and country name column, and mapped to different properties CountryCd, CountryDesc respectively.Step 4: Click submit.

You can see that the class gets mapped to new table.

What are the rules that get created by the wizard?

1. A new concrete class – Wizard creates a new concrete class that we provide.

2. New properties – You can check the external mappings tab.New properties are created for CountrCd, CountryDesc, sno

3. Database table instanceNow the connection is ready. When you save any page with class XYZ-PREM-Data-Countries it will make an entry to pr_xyz_data_countries.

 What do we need to remember when using the wizard?

  • You can substitute the same wizard process by manually creating the following rules.

Step 1: Create a concrete class with class which does not belong to a class group.

Step 2: Create database table instance by specifying the database name and table name. Save the instance.

Step 3: Save the class again and use test connectivity to check if the class is mapped to the database table.

Step 4: Create new properties corresponding to DB table column.

But creating via wizard is highly recommended.

  • You can also replicate the same process using Integration – Connector & metadata accelerator.

Connector & metadata accelerator are mainly used for integration with external database. We will discuss that in detail in separate lesson.

  1. Dhanu Dhanu

    Good read. Could you also update the post with column population job.

    • prem prem

      Sure, but I planned to publish it separate topic.. will get it soon😊

  2. Yogesh Yogesh

    Hi
    Can u update the details regarding external database I.e how to insert New table in external db by using pega application

    • prem prem

      Bro. I will get that done. Give me some time. I am switching my work to new laptop shortly. Some DB config issue us there

  3. Abhinav Abhinav

    Can you please share more details about split schema

    • Premkumar G Premkumar G

      Sure Abhinav. I will keep it in mind. I will try to post it soon 🙂

  4. pradeep reddy pradeep reddy

    HI please tell me about rules availability and rules resolution with clear examples

    Thanks

    • Premkumar G Premkumar G

      Hi Pradeep, you can expect an exclusive post on rule availability with examples within a week. Stay tuned 🙂

    • pradeep pradeep

      Thanks u very much prem for posting rule availability it’s very helpful to me. please post how to do exceptions in integration and in activities. it is available in pdn but it is very difficult to understand .

      • Premkumar G Premkumar G

        You are most welcome, Pradeep. 🙂
        Yeah, I’ve taken note of those topics. I’ll try my best to post them soon. I’ll help you in all the possible ways. 🙂
        Stay tuned.

  5. swapna swapna

    Its good. I need a situation where we use this in the real time project.

    • Premkumar G Premkumar G

      You have created a new data table in database with the help of DB administrators.
      You need to map a Pega class to that table. In such scenario, you can make use of that database class mapping wizard.

  6. Prashanthi Prashanthi

    Hi Prem,

    Here I have one question, I mapped a class to x table, but I want change the mapping.
    How can I do that ? can you please tell me

  7. vinod kumar vinod kumar

    i need some more info please share it i loss interview with one question only
    1. in real time develoer deal with database
    2. how to map class with database in real time developer will do this thing
    3.in real time we have external database in our system like oracle or else it connect with external in database where how to we connect
    4. how to fetch data pages in real time
    pls ans these qs it so help full to me

  8. Ankit Ankit

    Hi Prem,

    I am still confused about what Pega Rules and Pega Data stores? Pega Rules contains all the rules table but when we create a case type (as shown in the above example) it is stored at Pega Data. Can you please elaborate it?

    Also if possible can you please post for Decision Designing.

    Thanks for all your post. It’s really helpful.

    Please carry

  9. Ajay Ajay

    Hi Prem,

    It is very much help full and it is very clear.I have a small doubt, in java we are saving all the code in repositories like tortoise and many other so here in pega it is rules so can i consider all the rule data are saved in Database.Means Tortoise repository is database in pega.
    I may be wrong in comparison can you please help on this question.

  10. Srikanth Srikanth

    Hi Prem,

    As Abhinav said Required more details Split Schema me too waiting for same post,
    So that I clearly understand about DB??

  11. Gangadhar Gangadhar

    Hi prem,

    i have a doubt that,if i create a properties in work- class then how can i use this properties in data – class.and how can i save this in data table.please the answer.

    Regards.

    • Premkumar G Premkumar G

      Hi Gangadhar, the inheritance path of work class and data class meet by @baseclass only. So unless the property is in @baseclass, it cannot be reused in work- and data- class. I would recommend you to create a separate property in work and data class. Hope you are clear now

  12. Shweta Bhatia Shweta Bhatia

    Great article.. very helpful

    When we explicitly create a DataType , we never create a data table corresponding to it and we just add properties to it and save it. Does pega automatically creates a table for it in PegaRules?
    If so what is the use of this wizard?
    Can you please help by providing its use how to connect to external table and fetching data from it?

  13. pragya pragya

    Thanks for the awesome post. Could you please give some real time scenarios when we go for database class mapping?

    Could you also explain how and when to configure external database and is the database class mapping logic also applicable for external database?

  14. Chandan KK Chandan KK

    How do we expose all columns of a data table ?
    Can it be done through Declare Trigger..please correct me if i am wrong??

  15. Mrinal Mrinal

    u are dooing an awesome job
    plz keep uploading more topics
    thank u for such a great work
    can u upload on topics like connector and services

  16. Sonkar Sonkar

    @Prem Your posts are really helpful, much appriciated.

  17. Kunal Kunal

    Thank you for the post . It was awesome . Could you please post how can we map external database to the Pega class .

    Thanks in advance 🙂

  18. Bharadwaj Bharadwaj

    What is the instance class for application and ruleset in pega

  19. Suresh Y Suresh Y

    Hi Prem,

    You are designing this course in a very well manner, Its very understandable to a person who has very simple basic knowledge in pega. Thank You Very Much for your very valuable time and efforts for us.

    I have one query here:

    1)When creating a class and DB Table instance, we need two prerequisites like DB Table and columns ready.
    2)Is this same for the class group tables also.(Work- inherited classess)

    Thank You.

  20. Suresh Y Suresh Y

    Hi Prem,

    You are designing this course in a very well manner, Its very understandable to a person who has very simple basic knowledge in pega. Thank You Very Much for your very valuable time and efforts for us.

    I have one query here:

    1)When creating a class and DB Table instance, we need two prerequisites like DB Table and columns ready.
    2)Is this same for the class group tables also.(Work- inherited classes)

    Thank You.

  21. Mani Mani

    Hi Prem,

    Thanks for the post. My question here is while the wizard generating the properties, for some reason it is taking all the number data types of the columns to the decimal property types. So, I had to delete those properties and recreate them with number property type. Can you please suggest me how can I solve this issue?

    Thanks.

  22. Rakesh Rakesh

    Hello Prem,
    Its very informative post.
    Any plan to make a post on Database mapping to SQL Server tables?
    I’m trying it on 7.1.9, but not able to do so. Looks the system is not able to detect the sql connector jar file.

  23. kumar kumar

    Hi prem,
    can we delegate this database class
    if yes, can you explain.

  24. Divya Divya

    Hi Prem, Could you please explain how to configure PEGA pulse

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!