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

    EJB 3.0 with Oracle outside application container

    apachejo

      Hello,
      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.

      -----------------PERSISTENCE.XML-------------------------------

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence>
       <persistence-unit name="titan" transaction-type="RESOURCE_LOCAL">
       <class>com.titan.domain.Reservation</class>
       <class>com.titan.domain.Customer</class>
       <class>com.titan.domain.Address</class>
       <class>com.titan.domain.Cabin</class>
       <class>com.titan.domain.CreditCard</class>
       <class>com.titan.domain.CreditCompany</class>
       <class>com.titan.domain.Cruise</class>
       <class>com.titan.domain.Name</class>
       <class>com.titan.domain.Phone</class>
       <class>com.titan.domain.Ship</class>
       <properties>
       <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"/>
       </properties>
       </persistence-unit>
      </persistence>





      ------------------------Reservation.java--------------------------

      package com.titan.domain;
      
      
      import javax.persistence.*;
      import java.util.*;
      
      @Entity
      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; }
      
       @ManyToOne
       @JoinColumn(name="CRUISE_ID")
       public Cruise getCruise() { return cruise; }
       public void setCruise(Cruise cruise) { this.cruise = cruise; }
      
       @ManyToMany
       @JoinTable(name="RESERVATION_CABIN",
       joinColumns={@JoinColumn(name="RESERVATION_ID")},
       inverseJoinColumns={@JoinColumn(name="CABIN_ID")})
       public Set<Cabin> getCabins() { return cabins; }
       public void setCabins(Set<Cabin> cabins) { this.cabins = cabins; }
      
       @ManyToMany
       @JoinTable(name="RESERVATION_CUSTOMER",
       joinColumns={@JoinColumn(name="RESERVATION_ID")},
       inverseJoinColumns={@JoinColumn(name="CUSTOMER_ID")})
       public Set<Customer> getCustomers() { return customers; }
       public void setCustomers(Set<Customer> customers) { this.customers = customers; }
      }