0 Replies Latest reply on Jul 26, 2006 1:11 PM by Daniel Jones

    EJB 3.0 with Oracle outside application container

    Daniel Jones Newbie

      I am running the examples in the workbook using Eclipse 3.2 and using a local Oracle 10g database. By modifying a few things, I have successfully run all the examples except for those that run outside the application container ('transaction-type="RESOURCE_LOCAL"').

      The problem I encounter is that Hibernate will not generate all the tables. Additionally, I will receive class not found exceptions unless I include elements in the persistence.xml file (not included in the workbook example files).

      I am currently trying to run the examples from Exercise 9.1. My persistence.xml file is currently configured as listed below. Notice that I added the elements for each com/titan/domain type. If I do not do this then no tables are generated. After including these elements the following tables are generated - ADDRESS, CABIN, CREDITCOMPANY, CRUISE, CUSTOMER, RESERVATION_CABIN, RESERVATION_CUSTOMER, and SHIP. Notice that the table RESERVATION is not generated and therefore the type member InitializeDB.initialize fails on the first query of the RESERVATION table. I have not changed any of the provided application code. My Reservation.java code is list below.

      Does anyone have any idea why the tables are not generating properly?

      Also, why are the tables not generated using the annotations alone? In other words, why do I have to add the elements to the persistence.xml file when these elements are not included in the sample file?

      After looking at some hibernate documentation, I was unable to find details about the different property elements listed in the persistence.xml and what each of their values mean. Does anyone know of a good reference for this? I was trying different options for the 'hibernate.hbm2ddl.auto' property to see if that would help ('update', 'create', 'create-drop', etc.).

      Thank you.


      <?xml version="1.0" encoding="UTF-8"?>
       <persistence-unit name="titan" transaction-type="RESOURCE_LOCAL">
       <property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
       <property name="hibernate.connection.username" value="titan"/>
       <property name="hibernate.connection.password" value="titan"/>
       <property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:OracleDB"/>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
       <property name="hibernate.show_sql" value="true"/>


      package com.titan.domain;
      import javax.persistence.*;
      import java.util.*;
      public class Reservation implements java.io.Serializable
       private static final long serialVersionUID = 99l;
       private int id;
       private Date date;
       private double amountPaid;
       private Cruise cruise;
       private Set<Cabin> cabins = new HashSet<Cabin>();
       private Set<Customer> customers = new HashSet<Customer>();
       @Id @GeneratedValue
       public int getId() { return id; }
       public void setId(int id) { this.id = id; }
       public Date getDate() { return date; }
       public void setDate(Date date) { this.date = date; }
       public double getAmountPaid() { return amountPaid; }
       public void setAmountPaid(double amount) { amountPaid = amount; }
       public Cruise getCruise() { return cruise; }
       public void setCruise(Cruise cruise) { this.cruise = cruise; }
       public Set<Cabin> getCabins() { return cabins; }
       public void setCabins(Set<Cabin> cabins) { this.cabins = cabins; }
       public Set<Customer> getCustomers() { return customers; }
       public void setCustomers(Set<Customer> customers) { this.customers = customers; }