diff --git a/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Company.java b/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Company.java new file mode 100644 index 0000000000..47b0f8d285 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Company.java @@ -0,0 +1,71 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third- + * party contributors as indicated by the @author tags or express + * copyright attribution statements applied by the authors. + * All third-party contributions are distributed under license by + * Red Hat, Inc. + * + * This copyrighted material is made available to anyone wishing to + * use, modify, copy, or redistribute it subject to the terms and + * conditions of the GNU Lesser General Public License, as published + * by the Free Software Foundation. + * + * This program 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 distribution; if not, write to: + * + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ + +package org.hibernate.test.annotations.inheritance.joined; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.SecondaryTable; +import javax.persistence.Table; + +/** + * @author Sharath Reddy + * + */ +@Entity +@Table(name = "Company") +@SecondaryTable(name = "CompanyAddress") +public class Company extends Customer { + + private String companyName; + private String companyAddress; + + @Column + public String getCompanyName() { + return companyName; + } + + public void setCompanyName(String companyName) { + this.companyName = companyName; + } + + @Column(table = "CompanyAddress") + public String getCompanyAddress() { + return companyAddress; + } + + public void setCompanyAddress(String companyAddress) { + this.companyAddress = companyAddress; + } + + + + + + + +} diff --git a/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Customer.java b/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Customer.java new file mode 100644 index 0000000000..90940696a7 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Customer.java @@ -0,0 +1,67 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third- + * party contributors as indicated by the @author tags or express + * copyright attribution statements applied by the authors. + * All third-party contributions are distributed under license by + * Red Hat, Inc. + * + * This copyrighted material is made available to anyone wishing to + * use, modify, copy, or redistribute it subject to the terms and + * conditions of the GNU Lesser General Public License, as published + * by the Free Software Foundation. + * + * This program 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 distribution; if not, write to: + * + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ + +package org.hibernate.test.annotations.inheritance.joined; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.SecondaryTable; +import javax.persistence.Table; +import javax.persistence.InheritanceType; + +/** + * @author Sharath Reddy + * + */ +@Entity +@Inheritance(strategy = InheritanceType.JOINED) +@Table(name = "Customer") +@SecondaryTable(name = "CustomerDetails") +public class Customer extends LegalEntity { + + public String customerName; + public String customerCode; + + @Column + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String val) { + this.customerName = val; + } + + @Column(table="CustomerDetails") + public String getCustomerCode() { + return customerCode; + } + + public void setCustomerCode(String val) { + this.customerCode = val; + } +} \ No newline at end of file diff --git a/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java b/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java index 6ad8537770..4334df1854 100755 --- a/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java +++ b/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java @@ -167,6 +167,38 @@ public void testManyToOneWithJoinTable() { s.close(); } + /** + * HHH-4240 - SecondaryTables not recognized when using JOINED inheritance + */ + public void testSecondaryTables() { + + Session s = openSession(); + s.getTransaction().begin(); + + Company company = new Company(); + company.setCustomerName("Mama"); + company.setCustomerCode("123"); + company.setCompanyName("Mama Mia Pizza"); + company.setCompanyAddress("Rome"); + + s.persist( company ); + s.getTransaction().commit(); + s.clear(); + + s = openSession(); + s.getTransaction().begin(); + company = (Company) s.get( Company.class, company.getId()); + assertEquals("Mama", company.getCustomerName()); + assertEquals("123", company.getCustomerCode()); + assertEquals("Mama Mia Pizza", company.getCompanyName()); + assertEquals("Rome", company.getCompanyAddress()); + + s.delete( company ); + s.getTransaction().commit(); + s.close(); + } + + // public void testManyToOneAndJoin() throws Exception { // Session session = openSession(); // Transaction transaction = session.beginTransaction(); diff --git a/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/LegalEntity.java b/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/LegalEntity.java new file mode 100644 index 0000000000..742ca568e5 --- /dev/null +++ b/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/LegalEntity.java @@ -0,0 +1,56 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third- + * party contributors as indicated by the @author tags or express + * copyright attribution statements applied by the authors. + * All third-party contributions are distributed under license by + * Red Hat, Inc. + * + * This copyrighted material is made available to anyone wishing to + * use, modify, copy, or redistribute it subject to the terms and + * conditions of the GNU Lesser General Public License, as published + * by the Free Software Foundation. + * + * This program 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 distribution; if not, write to: + * + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ + +package org.hibernate.test.annotations.inheritance.joined; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +/** + * @author Sharath Reddy + * + */ +@MappedSuperclass +public class LegalEntity { + + private Long id; + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + + +}