Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
manjunath_b
Advisor
Advisor


This post is part of a 3-part series about HCP Persistence Service ASE.

Part1 is an overview of ASE DBaaS on the HANA Cloud Platform, and

Part2 about connecting to ASE on HCP using Eclipse.

 

In this post, we will look at binding an ASE DB instance to a Java application and connecting with it using a JPA sample application.

 

 

Prerequisites:



  • You should have Maven installed on your system.

  • You should have an ASE DB instance created in your account (refer to Part 2 of the series for detailed steps).

  • You should have opened a database tunnel to the ASE instance and connected to it using the Eclipse Data Platform (refer to Part 2 of the series for detailed steps).


 

 

Deploy sample application:


 

The HANA Cloud Platform SDK provides a set of sample applications which can be used to try out different functionalities on the HCP. One such application is the ‘persistence-with-jpa’ application. We will use this application to check the binding and working of the ASE DB instance on HCP.

 

The sample applications can be found in your SDK under the path /samples/persistence-with-jpa/. There should be a target folder with the persistence-with-jpa.war file present in it.

 

If not, we need to build the application using maven. Using the command prompt, navigate to the /samples/persistence-with-jpa/ folder, containing the pom.xml file and run the following command to create the war file.

 

                mvn package

 

The build should result in a Success, thus creating the target folder and within it the persistence-with-jpa.war file.

 



 

We will now deploy this file on the HCP account to continue this exercise.

 

  • Open the HCP cockpit for your account and navigate to Applications -> Java Applications. The Java Applications deployed on your account should be listed.




 

  • Click on Deploy Application to open the Deploy Application dialog. In this dialog, enter the details as follows:




    1. Browse and select the .war file built in the previous section using the Browse… option corresponding to WAR File Location:. The .war file should be present in the SDK path /samples/persistence-with-jpa/target/persistence-with-jpa.war.

    2. Change the Application Name: to ‘persistencejpa’.



 

    Select the additional parameters as per your account configuration / as needed:





    1. Select the Runtime Name: as needed

    2. Select the Compute Unit Size: as allocated to your account

    3. Enter the Min and Max for Number of Processes:

    4. Select the correct JVM Version: as needed



     Click on Deploy.







  • The WAR File will be uploaded to your HCP account and will be deployed. Wait till you get the message that the application is successfully deployed.




 

  • Click on Start on the Deploy Application dialog. The application will be added to the list of deployed applications in your account and will go to the Starting state.




 

  • Wait till the application state changes to Started. The application is now deployed and ready to use.




 

 

Create Data Source Binding for the application:


 

  • Click on the link which has the application name, in my case, persistencejpa. The application overview page is displayed, which shows the state of the application as Started and the Application URLs which can be used to access the application.






 

  • On the left hand pane, navigate to Configuration -> Data Source Bindings.


    

 

  • The application data source bindings page should be displayed, showing the list of data sources which have been bound to the application (Currently none). Click on New Binding to open the New Binding dialog.




 

  • In this dialog, we will reuse the ASE DB instance which we created in Part2 of the series. If you have not created this instance, please refer the steps in that post. Enter the details of the ASE instance as follows:





      1. Data Source: <default>

      2. DB/Schema ID: <select the database id of the ASE instance> E.g. asedemo

      3. Database User: <enter the user for the ASE instance> E.g. DBUSER

      4. Password: <enter the password for the ASE instance>

      5. Select the Verify credentials option




             Click on Save.






  • If all goes fine, the database instance should be added as a data source to this application.




 

  • We need to restart the application for the data source binding to take effect. Click on Overview on the left hand navigation pane, to return to the overview page.




 

  • Click on Stop, confirm the warning by clicking on OK and wait till the status changed to Stopped.






 

  • Click on Start and will till the status of the application changes to Started.




 

Note: You should open a database tunnel using the HANA Cloud Platform Console Client and connect to the ASE instance on HCP using Eclipse, Data Source Explorer view. (Detailed steps are outlined in Part2 of the series).

 

 

Run the application and verify the results:


 

We will run the persistencejpa application we deployed and create Person entities in the ASE database via the application UI and verify the creation in the backend using Eclipse.

 

  • Click on the Application URLs to launch the application in a new tab. If the database already has Person records created then the entries in the database must be listed. Else it should show that the database is empty. There must be two input boxes for First name and Last name. Additionally a button Add Person should be displayed to add Person entities to the database.




 

  • Enter ‘hcp’ in First name: ‘user’ in Last name: and click on Add Person. The record should be created and added to the list Entries in the Database.






 

In the background, the sample application has JPA code written which creates a table T_PERSON in the ASE DB which is bound to the application.

The table has 3 columns: ID (auto-generated, sequential), FIRSTNAME and LASTNAME.

 

Note: If you are interested, then navigate to the following path in your SDK to view the source code which uses JPA for table creation:

/samples/persistence-with-jpa/src/com/sap/cloud/sample/persistence. The code creates a Person entity with 3 members. Then JPA creates a table T_PERSON from the Person entity.

 

  • In Eclipse, Data Source Explorer view, expand the Database connection created and navigate to Databases -> NEO_<GUID> -> Tables and verify that the table T_PERSON is created.




 

  • Right click on the table and in the context menu choose Data -> Sample Contents.




 

 

  • The SQL Results view opens with the Result tab displaying the record you created using the deployed application UI.




 

Done! You have successfully deployed a sample JPA application on HCP, added an ASE DB instance as Data Source Binding, created new records in the ASE DB using the application UI and verified the records created in the database using Eclipse!!


1 Comment