Skip to Content

How to persist custom data in SAP PI java table – Part 2

In part-1 we created table in java dictionary and deployed it on SAP PI server. And we also created Entity bean class for the table. Next we have to create EAR project for the EJB entity bean and create session bean to access entity bean and deploy it in the java server.

STEP 3: Create EAR project for the entity bean project.

Select File > New > Other


Select Development Infrastructure > Development Component and click Next


Select Java EE > Enterprise Application and click Next


Select MyComponents and click Next


Provide Development Component Name and click Next


Select the EJB project and click Finish


STEP 4: Create JDBC DataSource Alias

Open SAP PI NWA and navigate to Configuration > Infrastructure > Application Resource and create new JDBC DataSource Alias


Provide DataSource Alias Name and Select DataSource Name (In format SAP<SID>DB) and click save


STEP 5: Create DataSource Descriptor for EAR project

Right click the EAR project and select properties


Select Project Facets and check SAP Data Source Aliases Provider Module and click OK


In project explorer Expand the EAR project and navigate to META-INF and double click on data-source-aliases.xml


Select General tab and expand to Aliases > ${} and give the DataSource Alias name created in previous step and save it.


STEP 6: Create Session Bean to Access Entity Bean

For the session bean to access the entity bean, we must create persistence descriptor in EJB project to identify datasource

Right click on EJB project and select properties. Click on project Facets and check Java Persistence and click OK


In project explorer, Expand the EJB project > ejbModule > META-INF and open persistence.xml in XML editor and add jta-data-source to persistence-unit


Provide Persistence-unit name and enter the datasource alias name created previously


Right click on EJB project and Select New > Session Bean


Enter package, class name and check Local business interface and provide local interface name and click Finish


Add @Webservice and @PersistenceContext annotations in the session bean


Add methods to create, read, update and delete rows in the table in the session bean

Create method:


Read method:


Update method:


Delete method:


Get all rows in the table:


Add the methods to the local interface to expose the methods to local clients. Right click on method and Select EJB Methods > Add to Local Interfaces


Local interface should look this


Right click on EJB project and Select Development Component > Build


Right click on EAR project and Select Development Component > Deploy


Deployment should be successful without errors

STEP 7: Add authentication to the webserivce deployed

Open NWA in SAP PI and navigate to SOA > Application and Scenario Communication > Single service administration and search for the service deployed


Select Configuration tab below and select the endpoint and click edit button below it


Select Security tab and check  User ID/Password in HTTP authentication and save it


Next steps are covered in Part 3

You must be Logged on to comment or reply to a post.