1 Reply Latest reply: Jun 4, 2013 10:54 AM by Michael OBrien RSS

    Database access from Oracle Java Cloud Service application

      I have registered for Oracle Java Cloud Service for trial period. I want to deploy a Spring MVC 3.2 and Hibernate 4.0 web application.

      I created a table in the Database Cloud. I am not sure how do I access the Database Cloud Service from my application.

      Need your guidance/pointers/references that can help me establish connection from my application to the database.

        • 1. Re: Database access from Oracle Java Cloud Service application
          Michael OBrien
          Use JPA - see the visitors example, it uses @PersistenceUnit injection with previously weaved .class entity files.
          You can use application managed EMF's and EntityManagers with code like the following - which is not preferable to using @PersistenceContext injection on an @Stateless session EJB but...

                    EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPAServletPU");
                    EntityManager em = emf.createEntityManager();
                    EntityTransaction transaction = null;
                    try {
                         transaction = em.getTransaction();
                         Visitor entity = new Visitor();
                         System.out.println("Committing: " + entity);
                    } catch (Exception e) {
                    } finally {

          Use a persistence.xml like the following

          <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
          <persistence-unit name="JPAServletPU" transaction-type="JTA">
               <property name="eclipselink.target-database" value="Oracle10g" />
          <property name="eclipselink.ddl-generation" value="create-tables"/>
          <!-- property name="eclipselink.ddl-generation" value="drop-and-create-tables"/-->

          Check out a tutorial on WebLogic JPA ORM usage here to get started as well.