Skip to Content

How to I find out where my code is running?

We are using JPA. If we want to debug, we need to do this on the Local SAP NetWeaver Cloud server. When running on the local server, we currently comment out this line - which we need when running on SAP NetWeaver Cloud. One idea was to find out in our coding on which server we are running.

1. Is there a way to get this information?

2. Is there a better way to run the code on the local SAP NetWeaver Cloud without changing the coding?

Thanks Frank

entityManagerProperties.put(

"eclipselink.target-database", "com.sap.persistence.platform.database.HDBPlatform");

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Nov 20, 2012 at 06:02 PM

    Hi Frank,

    asuming you want to know which DB platform your code is running against you might want to try a code snippet that is used in our tutorial Adding Persistence Using JPA (SDK 1.x) (https://help.netweaver.ondemand.com/default.htm?add_persistence_neo.html#concept_BE64823733A746719F68E91FE6404C97_75) in the init() method of class PersistenceWithJPAServlet:

              try {
                   InitialContext ctx = new InitialContext();
                   ds = (DataSource) ctx.lookup("java:comp/env/jdbc/DefaultDB");
    
                   Map properties = new HashMap();
                   properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, ds);
                   String databaseProductName = ds.getConnection().getMetaData()
                             .getDatabaseProductName();
                   if (databaseProductName.equals("HDB")) {
                        properties.put("eclipselink.target-database",
                                  "com.sap.persistence.platform.database.HDBPlatform");
                   }
                   emf = Persistence.createEntityManagerFactory(
                             "persistence-with-jpa", properties);
              } catch (NamingException e) {
                   throw new ServletException(e);
              } catch (SQLException e) {
                   LOGGER.error("Could not determine database product.");
                   throw new ServletException(e);
              }
    
    

    Best Regards,

    Bernd

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.