SAP HCP openSAP course guide week 2
[Update: This course is being repeated with updates]
Hi everyone, please be informed that the course “Introduction to SAP HANA Cloud Platform” was updated with new functionalities of the platform. Some of the units from the first course in 2013 no longer work seamlessly. To avoid issues on your side, please look into the repetition of the course “Introduction to SAP HANA Cloud Platform”. There is also a course guide available with the links to all blog posts I wrote for the updated course.
Course Guide Week 2 – Persistency Basics
Hi everyone,
in the second week of the course Introduction to SAP HANA Cloud Platform we will provide you with some basics around the usage of the Persistence Service of our platform.
Find below additional information that can be useful to you during this course week. While monitoring the forums I’ll also add some sections around common mistakes and how to fix them into the corresponding units.
Table of Contents
- [Update: This course is being repeated with updates]
- Course Guide Week 2 – Persistency Basics
- Table of Contents
- Unit 1 – Introduction & First Steps With EJB
-
Unit 2 – Connecting To Your Database
-
Common issues while opening the db tunnel
- “Command [open-db-tunnel] not found”
- “Host [hanatrail.ondemand.com] cannot be accessed. HTTPS proxy settings not found”
- “Host [proxy] cannot be accessed”
- “‘.’ is not recognized as an internal or external command, operable program or batch file”
- After connecting to the tunnel,the connection properties does not show the instance number
- “Detected attempt to connect with invalid user: “DEV_XXX” ” after opening the tunnel
- SSL certification error when trying to add a new system in Hana Studio
- Proxy settings
- Additional Links
-
Common issues while opening the db tunnel
- Unit 3 – Creating A JDBC Application
- Unit 4 – Sharing Data Between Applications
- Unit 5 -Using Multiple Databases
Unit 1 – Introduction & First Steps With EJB
Common Issues
Persistence operation failed with reason: The bean encountered a non-application exception
When inserting a value in the ejb sample’s UI he following exception is displayed:
Persistence operation failed with reason: The bean encountered a non-application exception; nested exception is: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services – 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: [274]: inserted value too large for column: 49620af6-80cd-454b-a95b-258eab7e287c Error Code: 274 Call: INSERT INTO T_PERSONS (ID, FIRSTNAME, LASTNAME) VALUES (?, ?, ?) bind => [3 parameters bound] Query: InsertObjectQuery(com.sap.cloud.sample.persistence.Person@8de9f444)
Solution: You’re using HANA schema without setting the additional property: <property name=”eclipselink.target-database” value=”com.sap.persistence.platform.database.HDBPlatform”/> in the persistence.xml.
1. go the cockpit -> Your application -> Database Schemas and delete the schema of the application.
2. set the property in persistence.xml
3. deploy/run the application again
MaxDB, HANA database, and the Target Database
Some participants realized that after deployment of their application they ended up with a schema on a MaxDB rather than a HANA database. You can check this in the Cloud Cockpit. Just click on Database Schemas and check the database type of your schema.
In the course you learned how to set the target database to com.sap.persistence.platform.database.HDBPlatform. (in the video this step has been shown at around 10:20). It is necessary to instruct EclipseLink to use HANA specific commands, types, etc. to access (an already existing) HANA database. However, it does not create a schema on a HANA database.
Actually a schema is created when an application is deployed in the cloud for the first time. The DB type that is used depends on the default settings that you can control in the Cloud Cockpit. So what you have to do in addition is to change the default settings in the Cloud Cockpit to HANA as described in Changing the Default Database and deploy your application with a new name (that forces the creation of a new schema).
I don’t see the JPA Content object in my eclipse IDE
- Right Click on your JPA project, in the menu which appears click on properties.
- In the properties window Select Project Facets.
- If Project Facets are not displayed click on link saying convert to facetted project.
- If Facets already available select Checkbox against JPA.
- Below the Properties window a link appears “Further configurations required”.
- Click on this link.
- In JPA facets window which appears select EclipseLink 2.X.X from Platform drop down and Disable Library Configuration from JPA Implementation drop down.
- Click OK
The JPA Content should appear now.
Additional Links
- About EJB (Enterprise Java Beans): http://en.wikipedia.org/wiki/Enterprise_JavaBeans
Unit 2 – Connecting To Your Database
Common issues while opening the db tunnel
“Command [open-db-tunnel] not found”
Solution: use the newest version of the Java EE 6 sdk from https://tools.hana.ondemand.com/sdk/ this command is pretty new and can be missing in some older sdk versions
If you call “neo -help” it will list all the commands supported in this SDK. The open-db-tunnel command if is listed in the “persistence” group.
“Host [hanatrail.ondemand.com] cannot be accessed. HTTPS proxy settings not found”
Solution:
1. Check the spelling of the host you provide in the command it should be hanatrial.ondemand.com.
2. Set up a proxy: Check the section below: “Should I use a proxy?”
“Host [proxy] cannot be accessed”
Solution: Your proxy settings are either not correct or you don’t need to use a proxy at all. Check the section below: “Should I use proxy?”
“‘.’ is not recognized as an internal or external command, operable program or batch file”
Solution: You are calling ./neo.sh on windows. Windows users should use: neo.bat to execute the open-db-tunnel command.
After connecting to the tunnel,the connection properties does not show the instance number
Solution: Your schema is MaxDB so you don’t need the instance number to connect to it. However you cannot connect to a MaxDB schema using HANA Studio. You have two options:
- If you want to use HANA Studio follow these instructions to change your default database type and create a HANA schema:
- To change the default database type for your account follow the instructions described in Changing the Default Database.
- Then either delete your application schema so that the new deployment will create a new one or just deploy the application with a new name.
- If you want to continue using the MaxDB schema connect to it using the Eclipse Database Development perspective.
The corresponding documentation shows how to connect to a database not with the tunnel but with a remote accessing servlet – this is the predecessor of the db tunnel. However the only difference is that when you configure the database connection you have to provide the jdbc url, username and password provided by the tunnel output. In the MaxDB case you don’t need to know the instance number that’s why it is not printed by the tunnel.
“Detected attempt to connect with invalid user: “DEV_XXX” ” after opening the tunnel
Solution: When you add a new System in the HANA Studio there is an “Auto-reconnect” checkbox which is by default checked. So once a system is added in the HANA Studio it will try regularly to refresh the system and collect some meta-information. When the tunnel is closed the attempts to reconnect fail but when you open a new tunnel a new password will be created. The Studio however will try to reconnect with the old password which will result in authentication exceptions and that’s why you see the warning message in the console. If you don’t change the password in your system properties (in HANA Studio) fast enough the user will be locked after some time. The user will be unlocked next time you open the tunnel.
So you either have to immediately edit the password in HANA Studio every time you reconnect the tunnel or just un-select the “Auto-reconnect” checkbox when adding a new System (in this case you should refresh the system manually from the context menu).
SSL certification error when trying to add a new system in Hana Studio
Solution: Open the <HANA_studio_installation_folder>\hdbstudio.ini there should be a -vm parameter with value stating where the java.exe is located. (For example: C:\jdk1.7\bin\javaw.exe, usually in a new line just after the -vm parameter). Make sure that the VM used is Java 6 or Java 7. Sometimes when you have a previously installed old jdk the Hana Studio installer choose to use it.
Proxy settings
To be able to establish a database tunnel through the console client you need to have your proxy settings setup correctly. Just follow this instruction: https://help.hana.ondemand.com/help/frameset.htm?7613dee4711e1014839a8273b0e91070.html
Should I use a proxy?
Check in the Firefox (Chrom) what kind of settings do you have for the proxy. Open “Tools”->”Options”->”Network”-> “Settings” There should be one of the following options selected:
- No proxy – in this case you should set no proxy settings in both eclipse and command console
- Manual proxy settings – there should be a host and port which you should use both in eclipse and in command console (the syntax of the “set” command for the different operating systems can be seen in the <HCP_SDK_PATH>\tools\readme.txt file). <HCP_SDK_PATH> is the path in the file system where you unzipped the HANA Cloud Platform SDK.
- Automatic proxy configuration URL (something like: http://proxy:8083/). Copy and paste this URL in the browser and download the file it points to. You can open the file with Notepad. At the very end of this file should stay something like:
return “PROXY dxxx3proxy.yyy.zzz.corp:8080;PROXY proxy.xxx.yyy.corp:8080;”;
Use the proxy and port that are marked bold in eclipse and the Console Client (in this case PROXY and 8080)
Additional Links
- Developer Edition of SAP HANA Studio
- How to install SAP HANA Studio
- Syntax of the properties file provided in the console client commands
- Setting up the console client
Unit 3 – Creating A JDBC Application
Additional Links
- About JDBC (Java DataBase Connectivity): http://en.wikipedia.org/wiki/Jdbc
Hey Rui, It is very informative and knowledgeable blog as well as straight forward guide. Very good afford. thanks for sharing and keep it up
Arshiyan
Hello Rui,
Persistence service of SAP HANA Platform is quite interesting.
Now after deploying the application "persistance with ejb" in unit 1, when i enter the firstname & the lastname and click "Add Person", i get the following error:
I followed the note given in section "2.2 Maintain the metadata of the person entity" (from here we copied the Target Database for persistence.xml) and got same error.
Solution for this?
Thanks & Regards,
Prashant Soni
Hello Prashant,
Could it be that you deployed your application first and then changed the Target Database afterwards? In that case the table still exists with the wrong meta data still leading to the same error.
To get over this you have to delete the tables and create them anew. The easiest way to do this is using the "Drop and Create Tables" feature. Open the "Schema Generation" tab of the persistence.xml file and choose "Drop and Create Tables" in the "DDL generation type" field. Then redeploy your application again.
Of course, after successful deployment you should set this parameter back to "Create Tables". Otherwise you would always delete your tables during deployment.
Regards,
Bernd
PS: As this is a more general page with background information about the course I would recommend not to put questions here but rather use the discussion forum that has been provided for exactly this purpose. You'll find it here: https://open.sap.com/courses/7/discussion_topics (with specific sub forums for each week).
Thanks and Regards,
Bernd
Hi Rui,
I am wondering about 2 things:
1. when you said in Unit 5 "we copy the commands from slides (new method for the java servlet etc." where those slides are actually? I had to type the lines myself.
2. I compared the 2 types of loggers and could not find a difference, I even used "all" type.
Is any type will reveal the actual value which was sent to the database? Oracle has such a way. Thanks,Michael
Hi Rui,
I am having a problem in running the console client command prompt. Is this a separate command prompt or the standard Win 7 prompt ? Since you use a Mac its a bit confusing as the way you run (Right click on the Tools folder and run the services) is not available in Windows. Please let me know on this .
Regards,
Sandeep
Hi Sandeep,
this is the standard win7 prompt(cmd.exe). You need to open it and to navigate to the location of the "tools" folder. More details on setting up the console client you can find in the official documentation.
Best regards,
Nikolay
Thanks Nikolay, its clear now.
One more query regarding HANA Client and HANA Studio. As per the unit 2 , I have installed HANA studio. Do we also need to install HANA Client ? and access SAP HANA Repository ?
Regards,
Sandeep
Hi Sandeep,
You won't need the client for the JDBC application from week 2 of the course. Here you are installing it for remote database access. The client is necessary for developing HANA native applications.
Best regards,
Nikolay
Hi Rui,
great course! Keep it up!
Hi Rui,
I may sound silly but since am new to this please excuse me.
I could not find a create table query within the PersistencewithEJB sample. Neither could I find any select or insert options. I could understand from the java code that they have been formulated as a table using code. But when I connect to the HANA studio using the schema of the application even though I could not see the table getting created in the DEV account due to reasons that ELitsa had explained in one of the discussions, I could find the table getting created in the Neo account. I had tried modifying the application adding some more fields. Then also its working fine.
Is it the persistence service that is creating the query in the HANA DB or the EJB? Since I could find a datasource defining code in JDBC and in the slides also its mentioned that in JDBC "Initial creation of database structures required". And in JDBC also there is the use of persistence service. Am a lil confused here.
If am missing out something please let me know.
Thanks,
Meera
Hi Meera,
The EJB sample is using JPA and not JDBC. In JPA you just define your persistence units as java classes and then the JPA provider - in our case EclipseLink creates a table for every such class. In our case it creates a table T_PERSONS (there is an annotation in the Persistence class specifying the tables name) and columns - id, firstname and lastname. If you add more filends here the EclipseLink will add more columns.
If you look at the persistence.xml you'll see that the Person.class is listed there - this is the way to notify EclipseLink that it should create a table for it.
This is the biggest advantage of JPA compared to JDBC that you work only with java objects and the JPA takes care to translate the operations to SQL statements, execute them and then translate the results into java objects again.
Hope it's a bit clearer now.
Greetings,
Elitsa
Hi All,
I have another problem that I have ran into.
After I have received the logon details for creating a new system in HANA studio, I go to the user folder that should hold all the information I have entered into my application.
But the folders are empty and I receive an error saying that the Database connection is not available. Why would this be happening?
Surely the proxy settings are correct as I was given a valid user/password to connect the DB Tunnel. And the path is also correct.
So I am just wondering why is this happening?
Thanks.
Best Regards,
/Barry
Hi Barry,
Try deleting this system in HANA studio. Execute again the open-db-tunnel command so you get a new password and try adding the System again. Also make sure that the type of your schema is HANA (you can see this also in the output of the tunnel).
In the NEO_XXXXXXXXX schema -> Tables there should be the T_PERSONS table and if you have added some names in the application UI you should be able to see also them.
Hope that helps,
Greetings,
Elitsa
Hi Elitsa,
I now got it working.
Thank you for your assistance.
Thanks Elitsa.
Best Regards,
/Barry
Hi Everyone,
I have deployed the solution to the cloud.
And opened it through the Database Tunnel in HANA Studio,
But say for example a customer is using an application I have created, like a survey.
They apply all the data to this survey.
But they wont be able to see it because they wont be running an database tunnel.
How can I perform this without using a DB Tunnel?
Hi Barry, if you provide the data in an application that your customer can access, your customer doesn't need any DB tunnel. You provide the information to your customer via your application and that's it. If you want to restrict the access to these applications you can work with roles as described in week 4 of the course (user authentication and security).
Hope I've understood your use case correctly.
Best,
Rui
Hi RUi
Getting this error when clicking on application URL - I have maintained the HANA DB in the persistence.xml any ideas?
Persistence with EJB Sample!
Persistence operation failed with reason: The bean encountered a non-application exception; nested exception is: javax.persistence.PersistenceException: Exception [EclipseLink-7042] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.ValidationException Exception Description: Database platform class [com.sap.persistence.platform.database.HDBPlatform] not found. Internal Exception: java.lang.ClassCastException: class com.sap.persistence.platform.database.HDBPlatform:org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@55088a5f[org.eclipse.persistence.core:2.4.1.v20121003-ad44345(id=252)] incompatible with interface org.eclipse.persistence.internal.databaseaccess.Platform:org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@5e980724[persistence-with-ejb:0.0.0(id=301)]
thanks
Stephen
Just keep the default value. This is depend on the version and the change of the target is no longer required.
I get below error when in try to add cloud system>trial schema. i have provided correct host and correct credentials. i have default proxy setting i.e 'Native' as i am using home PC.
Please help
Hi everybody, this course is being repeated on openSAP. As some of the units have been re-recorded to reflect updates on the platform I highly recommend to look into the learning materials there instead of using the videos from the first course in 2013.
This is also the reason why I close this blog post for comments.
@Sneha: please post your question into the openSAP forum for the new introductory course or simply add it to the SCN Forum of the SAP HANA Cloud Platform.
Best,
Rui