[jboss-cvs] JBossAS SVN: r105313 - in projects/ejb-book/trunk/chxx-employeeregistry/src: main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 27 17:56:56 EDT 2010


Author: ALRubinger
Date: 2010-05-27 17:56:55 -0400 (Thu, 27 May 2010)
New Revision: 105313

Added:
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Customer.java
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Employee.java
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Person.java
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Customer.java
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Employee.java
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Person.java
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Customer.java
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Employee.java
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Person.java
Modified:
   projects/ejb-book/trunk/chxx-employeeregistry/src/main/resources/persistence.xml
   projects/ejb-book/trunk/chxx-employeeregistry/src/test/java/org/jboss/ejb3/examples/employeeregistry/EmployeeIntegrationTest.java
Log:
[EJBBOOK-27] Add inheritance examples for persistence

Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Customer.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Customer.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Customer.java	2010-05-27 21:56:55 UTC (rev 105313)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.joined;
+
+import javax.persistence.Entity;
+
+/**
+ * Represents a customer, a {@link Person}
+ * associated with a company.  Sits in the middle of an inheritance
+ * hierarchy and is extended by employee types, who are a special type of 
+ * {@link Customer}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity(name = "JOINED_CUSTOMER")
+public class Customer extends Person
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Street-level address
+    */
+   private String street;
+
+   /**
+    * City
+    */
+   private String city;
+
+   /**
+    * State
+    */
+   private String state;
+
+   /**
+    * ZIP
+    */
+   private String zip;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+   /**
+    * @return the street
+    */
+   public String getStreet()
+   {
+      return street;
+   }
+
+   /**
+    * @param street the street to set
+    */
+   public void setStreet(final String street)
+   {
+      this.street = street;
+   }
+
+   /**
+    * @return the city
+    */
+   public String getCity()
+   {
+      return city;
+   }
+
+   /**
+    * @param city the city to set
+    */
+   public void setCity(final String city)
+   {
+      this.city = city;
+   }
+
+   /**
+    * @return the state
+    */
+   public String getState()
+   {
+      return state;
+   }
+
+   /**
+    * @param state the state to set
+    */
+   public void setState(final String state)
+   {
+      this.state = state;
+   }
+
+   /**
+    * @return the zip
+    */
+   public String getZip()
+   {
+      return zip;
+   }
+
+   /**
+    * @param zip the zip to set
+    */
+   public void setZip(final String zip)
+   {
+      this.zip = zip;
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Employee.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Employee.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Employee.java	2010-05-27 21:56:55 UTC (rev 105313)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.joined;
+
+import javax.persistence.Entity;
+import javax.persistence.PrimaryKeyJoinColumn;
+
+/**
+ * Employee
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity(name = "JOINED_EMPLOYEE")
+ at PrimaryKeyJoinColumn(name = "EMP_PK")
+public class Employee extends Customer
+{
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * ID of the Employee
+    */
+   private Integer employeeId;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @return the employeeId
+    */
+   public Integer getEmployeeId()
+   {
+      return employeeId;
+   }
+
+   /**
+    * @param employeeId the employeeId to set
+    */
+   public void setEmployeeId(final Integer employeeId)
+   {
+      this.employeeId = employeeId;
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Person.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Person.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/joined/Person.java	2010-05-27 21:56:55 UTC (rev 105313)
@@ -0,0 +1,170 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.joined;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+/**
+ * Base class for entities representing a person
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity(name = "JOINED_PERSON")
+ at Inheritance(strategy = InheritanceType.JOINED)
+public class Person
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Primary key 
+    */
+   @Id
+   @GeneratedValue
+   private Long id;
+
+   /**
+    * First name of the person
+    */
+   private String firstName;
+
+   /**
+    * Last name of the person
+    */
+   private String lastName;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @return the id
+    */
+   public Long getId()
+   {
+      return id;
+   }
+
+   /**
+    * @param id the id to set
+    */
+   public void setId(final Long id)
+   {
+      this.id = id;
+   }
+
+   /**
+    * @return the firstName
+    */
+   public String getFirstName()
+   {
+      return firstName;
+   }
+
+   /**
+    * @param firstName the firstName to set
+    */
+   public void setFirstName(final String firstName)
+   {
+      this.firstName = firstName;
+   }
+
+   /**
+    * @return the lastName
+    */
+   public String getLastName()
+   {
+      return lastName;
+   }
+
+   /**
+    * @param lastName the lastName to set
+    */
+   public void setLastName(final String lastName)
+   {
+      this.lastName = lastName;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Overridden Implementations ---------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /*
+    * Value equality is based by ID and type only
+    */
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#hashCode()
+    */
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((id == null) ? 0 : id.hashCode());
+      return result;
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#equals(java.lang.Object)
+    */
+   @Override
+   public boolean equals(final Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      Person other = (Person) obj;
+      if (id == null)
+      {
+         if (other.id != null)
+            return false;
+      }
+      else if (!id.equals(other.id))
+         return false;
+      return true;
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      return this.getClass().getSimpleName() + " [firstName=" + firstName + ", id=" + id + ", lastName=" + lastName
+            + "]";
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Customer.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Customer.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Customer.java	2010-05-27 21:56:55 UTC (rev 105313)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.singleclass;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+/**
+ * Represents a customer, a {@link Person}
+ * associated with a company.  Sits in the middle of an inheritance
+ * hierarchy and is extended by employee types, who are a special type of 
+ * {@link Customer}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity(name = "SINGLECLASS_CUSTOMER")
+ at DiscriminatorValue("CUSTOMER")
+public class Customer extends Person
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Street-level address
+    */
+   private String street;
+
+   /**
+    * City
+    */
+   private String city;
+
+   /**
+    * State
+    */
+   private String state;
+
+   /**
+    * ZIP
+    */
+   private String zip;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+   /**
+    * @return the street
+    */
+   public String getStreet()
+   {
+      return street;
+   }
+
+   /**
+    * @param street the street to set
+    */
+   public void setStreet(final String street)
+   {
+      this.street = street;
+   }
+
+   /**
+    * @return the city
+    */
+   public String getCity()
+   {
+      return city;
+   }
+
+   /**
+    * @param city the city to set
+    */
+   public void setCity(final String city)
+   {
+      this.city = city;
+   }
+
+   /**
+    * @return the state
+    */
+   public String getState()
+   {
+      return state;
+   }
+
+   /**
+    * @param state the state to set
+    */
+   public void setState(final String state)
+   {
+      this.state = state;
+   }
+
+   /**
+    * @return the zip
+    */
+   public String getZip()
+   {
+      return zip;
+   }
+
+   /**
+    * @param zip the zip to set
+    */
+   public void setZip(final String zip)
+   {
+      this.zip = zip;
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Employee.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Employee.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Employee.java	2010-05-27 21:56:55 UTC (rev 105313)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.singleclass;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+/**
+ * Employee
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity(name = "SINGLECLASS_EMPLOYEE")
+ at DiscriminatorValue("EMPLOYEE")
+public class Employee extends Customer
+{
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * ID of the Employee
+    */
+   private Integer employeeId;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @return the employeeId
+    */
+   public Integer getEmployeeId()
+   {
+      return employeeId;
+   }
+
+   /**
+    * @param employeeId the employeeId to set
+    */
+   public void setEmployeeId(final Integer employeeId)
+   {
+      this.employeeId = employeeId;
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Person.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Person.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/singleclass/Person.java	2010-05-27 21:56:55 UTC (rev 105313)
@@ -0,0 +1,175 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.singleclass;
+
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+/**
+ * Base class for entities representing a person
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity(name = "SINGLECLASS_PERSON")
+ at Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+ at DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING)
+ at DiscriminatorValue("PERSON")
+public class Person
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Primary key 
+    */
+   @Id
+   @GeneratedValue
+   private Long id;
+
+   /**
+    * First name of the person
+    */
+   private String firstName;
+
+   /**
+    * Last name of the person
+    */
+   private String lastName;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @return the id
+    */
+   public Long getId()
+   {
+      return id;
+   }
+
+   /**
+    * @param id the id to set
+    */
+   public void setId(final Long id)
+   {
+      this.id = id;
+   }
+
+   /**
+    * @return the firstName
+    */
+   public String getFirstName()
+   {
+      return firstName;
+   }
+
+   /**
+    * @param firstName the firstName to set
+    */
+   public void setFirstName(final String firstName)
+   {
+      this.firstName = firstName;
+   }
+
+   /**
+    * @return the lastName
+    */
+   public String getLastName()
+   {
+      return lastName;
+   }
+
+   /**
+    * @param lastName the lastName to set
+    */
+   public void setLastName(final String lastName)
+   {
+      this.lastName = lastName;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Overridden Implementations ---------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /*
+    * Value equality is based by ID and type only
+    */
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#hashCode()
+    */
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((id == null) ? 0 : id.hashCode());
+      return result;
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#equals(java.lang.Object)
+    */
+   @Override
+   public boolean equals(final Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      Person other = (Person) obj;
+      if (id == null)
+      {
+         if (other.id != null)
+            return false;
+      }
+      else if (!id.equals(other.id))
+         return false;
+      return true;
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      return this.getClass().getSimpleName() + " [firstName=" + firstName + ", id=" + id + ", lastName=" + lastName
+            + "]";
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Customer.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Customer.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Customer.java	2010-05-27 21:56:55 UTC (rev 105313)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.tableperclass;
+
+import javax.persistence.Entity;
+
+/**
+ * Represents a customer, a {@link Person}
+ * associated with a company.  Sits in the middle of an inheritance
+ * hierarchy and is extended by employee types, who are a special type of 
+ * {@link Customer}.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity(name = "TABLEPERCLASS_CUSTOMER")
+public class Customer extends Person
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Street-level address
+    */
+   private String street;
+
+   /**
+    * City
+    */
+   private String city;
+
+   /**
+    * State
+    */
+   private String state;
+
+   /**
+    * ZIP
+    */
+   private String zip;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+   /**
+    * @return the street
+    */
+   public String getStreet()
+   {
+      return street;
+   }
+
+   /**
+    * @param street the street to set
+    */
+   public void setStreet(final String street)
+   {
+      this.street = street;
+   }
+
+   /**
+    * @return the city
+    */
+   public String getCity()
+   {
+      return city;
+   }
+
+   /**
+    * @param city the city to set
+    */
+   public void setCity(final String city)
+   {
+      this.city = city;
+   }
+
+   /**
+    * @return the state
+    */
+   public String getState()
+   {
+      return state;
+   }
+
+   /**
+    * @param state the state to set
+    */
+   public void setState(final String state)
+   {
+      this.state = state;
+   }
+
+   /**
+    * @return the zip
+    */
+   public String getZip()
+   {
+      return zip;
+   }
+
+   /**
+    * @param zip the zip to set
+    */
+   public void setZip(final String zip)
+   {
+      this.zip = zip;
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Employee.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Employee.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Employee.java	2010-05-27 21:56:55 UTC (rev 105313)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.tableperclass;
+
+import javax.persistence.Entity;
+
+/**
+ * Employee
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity(name = "TABLEPERCLASS_EMPLOYEE")
+public class Employee extends Customer
+{
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * ID of the Employee
+    */
+   private Integer employeeId;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @return the employeeId
+    */
+   public Integer getEmployeeId()
+   {
+      return employeeId;
+   }
+
+   /**
+    * @param employeeId the employeeId to set
+    */
+   public void setEmployeeId(final Integer employeeId)
+   {
+      this.employeeId = employeeId;
+   }
+
+}

Added: projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Person.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Person.java	                        (rev 0)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/java/org/jboss/ejb3/examples/employeeregistry/chyy/inheritance/tableperclass/Person.java	2010-05-27 21:56:55 UTC (rev 105313)
@@ -0,0 +1,172 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+  *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.tableperclass;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+/**
+ * Base class for entities representing a person
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+ at Entity(name = "TABLEPERCLASS_PERSON")
+ at Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+public class Person
+{
+
+   //-------------------------------------------------------------------------------------||
+   // Instance Members -------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * Primary key 
+    */
+   @Id
+   @GeneratedValue(strategy = GenerationType.TABLE)
+   // Cannot accept default generation strategy for table-per-class
+   private Long id;
+
+   /**
+    * First name of the person
+    */
+   private String firstName;
+
+   /**
+    * Last name of the person
+    */
+   private String lastName;
+
+   //-------------------------------------------------------------------------------------||
+   // Accessors / Mutators ---------------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /**
+    * @return the id
+    */
+   public Long getId()
+   {
+      return id;
+   }
+
+   /**
+    * @param id the id to set
+    */
+   public void setId(final Long id)
+   {
+      this.id = id;
+   }
+
+   /**
+    * @return the firstName
+    */
+   public String getFirstName()
+   {
+      return firstName;
+   }
+
+   /**
+    * @param firstName the firstName to set
+    */
+   public void setFirstName(final String firstName)
+   {
+      this.firstName = firstName;
+   }
+
+   /**
+    * @return the lastName
+    */
+   public String getLastName()
+   {
+      return lastName;
+   }
+
+   /**
+    * @param lastName the lastName to set
+    */
+   public void setLastName(final String lastName)
+   {
+      this.lastName = lastName;
+   }
+
+   //-------------------------------------------------------------------------------------||
+   // Overridden Implementations ---------------------------------------------------------||
+   //-------------------------------------------------------------------------------------||
+
+   /*
+    * Value equality is based by ID and type only
+    */
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#hashCode()
+    */
+   @Override
+   public int hashCode()
+   {
+      final int prime = 31;
+      int result = 1;
+      result = prime * result + ((id == null) ? 0 : id.hashCode());
+      return result;
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#equals(java.lang.Object)
+    */
+   @Override
+   public boolean equals(final Object obj)
+   {
+      if (this == obj)
+         return true;
+      if (obj == null)
+         return false;
+      if (getClass() != obj.getClass())
+         return false;
+      Person other = (Person) obj;
+      if (id == null)
+      {
+         if (other.id != null)
+            return false;
+      }
+      else if (!id.equals(other.id))
+         return false;
+      return true;
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see java.lang.Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      return this.getClass().getSimpleName() + " [firstName=" + firstName + ", id=" + id + ", lastName=" + lastName
+            + "]";
+   }
+
+}

Modified: projects/ejb-book/trunk/chxx-employeeregistry/src/main/resources/persistence.xml
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/main/resources/persistence.xml	2010-05-27 20:47:50 UTC (rev 105312)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/main/resources/persistence.xml	2010-05-27 21:56:55 UTC (rev 105313)
@@ -7,7 +7,7 @@
    <persistence-unit name="tempdb">
       <jta-data-source>java:/DefaultDS</jta-data-source>
       <properties>
-          <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+          <property name="hibernate.hbm2ddl.auto" value="create"/>
           <!-- 
           
           You can enable this for Hibernate to dump SQL output to STDOUT

Modified: projects/ejb-book/trunk/chxx-employeeregistry/src/test/java/org/jboss/ejb3/examples/employeeregistry/EmployeeIntegrationTest.java
===================================================================
--- projects/ejb-book/trunk/chxx-employeeregistry/src/test/java/org/jboss/ejb3/examples/employeeregistry/EmployeeIntegrationTest.java	2010-05-27 20:47:50 UTC (rev 105312)
+++ projects/ejb-book/trunk/chxx-employeeregistry/src/test/java/org/jboss/ejb3/examples/employeeregistry/EmployeeIntegrationTest.java	2010-05-27 21:56:55 UTC (rev 105313)
@@ -108,7 +108,10 @@
       final JavaArchive archive = ShrinkWrap.create("entities.jar", JavaArchive.class).addPackages(false,
             SimpleEmployee.class.getPackage(), EmployeeWithMappedSuperClassId.class.getPackage(),
             Employee.class.getPackage(), TxWrappingLocalBusiness.class.getPackage(),
-            EntityListenerEmployee.class.getPackage(), EntityManagerExposingBean.class.getPackage())
+            EntityListenerEmployee.class.getPackage(), EntityManagerExposingBean.class.getPackage(),
+            org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.singleclass.Employee.class.getPackage(),
+            org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.tableperclass.Employee.class.getPackage(),
+            org.jboss.ejb3.examples.employeeregistry.chyy.inheritance.joined.Employee.class.getPackage())
             .addManifestResource("persistence.xml");
       log.info(archive.toString(true));
       return archive;




More information about the jboss-cvs-commits mailing list