HHH-4240 - SecondaryTables not recognized when using JOINED inheritance

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19908 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Sharath Reddy 2010-07-07 14:05:01 +00:00
parent 80b082086e
commit 7697640089
4 changed files with 226 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -167,6 +167,38 @@ public class JoinedSubclassTest extends TestCase {
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();

View File

@ -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;
}
}