HHH-9390 : Default join column name (FK) for @ManyToMany uses owning entity primary table name (test cases)

(cherry picked from commit d4d5fcc9e2)
This commit is contained in:
Gail Badner 2014-09-11 12:49:44 -07:00
parent e4b0915a8e
commit f8af94e559
9 changed files with 16 additions and 85 deletions

View File

@ -30,8 +30,6 @@ import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import org.hibernate.test.annotations.manytomany.KnownClient;
/**
* @author Gail Badner
*/

View File

@ -7,8 +7,6 @@ import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import org.hibernate.test.annotations.manytomany.Item;
/**
* @author Emmanuel Bernard
*/

View File

@ -4,17 +4,15 @@ import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.ManyToMany;
import org.hibernate.test.annotations.manytomany.PhoneNumber;
@Embeddable
public class ContactInfo {
// @ManyToOne
// Address address; // Unidirectional
List<org.hibernate.test.annotations.manytomany.PhoneNumber> phoneNumbers; // Bidirectional
List<PhoneNumber> phoneNumbers; // Bidirectional
@ManyToMany(cascade= CascadeType.ALL)
public List<org.hibernate.test.annotations.manytomany.PhoneNumber> getPhoneNumbers() {
public List<PhoneNumber> getPhoneNumbers() {
return phoneNumbers;
}

View File

@ -13,9 +13,6 @@ import javax.persistence.InheritanceType;
import javax.persistence.ManyToMany;
import org.hibernate.annotations.Cascade;
import org.hibernate.test.annotations.manytomany.ContactInfo;
import org.hibernate.test.annotations.manytomany.Employer;
import org.hibernate.test.annotations.manytomany.JobInfo;
/**
* Employee in an Employer-Employee relationship
@ -27,10 +24,8 @@ import org.hibernate.test.annotations.manytomany.JobInfo;
@SuppressWarnings("serial")
public class Employee implements Serializable {
private Integer id;
private Collection<Employer> employers;
private String name;
ContactInfo contactInfo;
JobInfo jobInfo;
// ContactInfo is for ManyToMany testing
@Embedded
@ -42,17 +37,6 @@ public class Employee implements Serializable {
this.contactInfo = contactInfo;
}
// JobInfo is for OneToMany testing
@Embedded
public JobInfo getJobInfo() {
return jobInfo;
}
public void setJobInfo(JobInfo jobInfo) {
this.jobInfo = jobInfo;
}
@Column(name="fld_name")
public String getName() {
return name;
@ -71,18 +55,4 @@ public class Employee implements Serializable {
public void setId(Integer integer) {
id = integer;
}
@ManyToMany(
cascade = {CascadeType.PERSIST, CascadeType.MERGE},
mappedBy = "employees"
)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.PERSIST})
public Collection<Employer> getEmployers() {
return employers;
}
public void setEmployers(Collection<Employer> employers) {
this.employers = employers;
}
}

View File

@ -30,15 +30,13 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import org.hibernate.test.annotations.manytomany.*;
/**
* @author Gail Badner
*/
@Entity(name="ITEM")
public class Item {
private Integer id;
private Set<org.hibernate.test.annotations.manytomany.City> producedInCities;
private Set<City> producedInCities;
@Id
@GeneratedValue
@ -52,11 +50,11 @@ public class Item {
}
@ManyToMany
public Set<org.hibernate.test.annotations.manytomany.City> getProducedInCities() {
public Set<City> getProducedInCities() {
return producedInCities;
}
public void setProducedInCities(Set<org.hibernate.test.annotations.manytomany.City> producedInCities) {
public void setProducedInCities(Set<City> producedInCities) {
this.producedInCities = producedInCities;
}
}

View File

@ -6,8 +6,6 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import org.hibernate.test.annotations.manytomany.Store;
/**
* @author Emmanuel Bernard
*/

View File

@ -29,17 +29,8 @@ import org.junit.Test;
import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.test.annotations.manytomany.Category;
import org.hibernate.test.annotations.manytomany.City;
import org.hibernate.test.annotations.manytomany.Contractor;
import org.hibernate.test.annotations.manytomany.Employee;
import org.hibernate.test.annotations.manytomany.Employer;
import org.hibernate.test.annotations.manytomany.Item;
import org.hibernate.test.annotations.manytomany.KnownClient;
import org.hibernate.test.annotations.manytomany.PhoneNumber;
import org.hibernate.test.annotations.manytomany.ProgramManager;
import org.hibernate.test.annotations.manytomany.Store;
import org.hibernate.test.annotations.manytomany.Supplier;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.type.EntityType;
@ -168,6 +159,8 @@ public class ManyToManyDefaultsTest extends BaseCoreFunctionalTestCase {
}
@Test
@TestForIssue( jiraKey = "HHH-9390")
@FailureExpected( jiraKey = "HHH-9390")
public void testUnidirOwnerPrimaryTableAssocEntityNamePKOverride() {
// City.stolenItems; associated entity: Item
// City has @Entity with no name configured and @Table(name = "tbl_city")
@ -186,6 +179,8 @@ public class ManyToManyDefaultsTest extends BaseCoreFunctionalTestCase {
}
@Test
@TestForIssue( jiraKey = "HHH-9390")
@FailureExpected( jiraKey = "HHH-9390")
public void testUnidirOwnerEntityNamePrimaryTableOverride() {
// Category.clients: associated entity: KnownClient
// Category has @Entity(name="CATEGORY") @Table(name="CATEGORY_TAB")
@ -261,15 +256,11 @@ public class ManyToManyDefaultsTest extends BaseCoreFunctionalTestCase {
return new Class[]{
Category.class,
City.class,
Contractor.class,
Employee.class,
Employer.class,
Item.class,
KnownClient.class,
PhoneNumber.class,
ProgramManager.class,
Store.class,
Supplier.class
};
}
}

View File

@ -5,12 +5,10 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import org.hibernate.test.annotations.manytomany.Employee;
@Entity
public class PhoneNumber {
int phNumber;
Collection<org.hibernate.test.annotations.manytomany.Employee> employees;
Collection<Employee> employees;
@Id
public int getPhNumber() {
@ -22,7 +20,7 @@ public class PhoneNumber {
}
@ManyToMany(mappedBy="contactInfo.phoneNumbers", cascade= CascadeType.ALL)
public Collection<org.hibernate.test.annotations.manytomany.Employee> getEmployees() {
public Collection<Employee> getEmployees() {
return employees;
}

View File

@ -1,5 +1,6 @@
//$Id$
package org.hibernate.test.annotations.manytomany.defaults;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@ -10,10 +11,6 @@ import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import org.hibernate.test.annotations.manytomany.*;
import org.hibernate.test.annotations.manytomany.City;
import org.hibernate.test.annotations.manytomany.KnownClient;
/**
* @author Emmanuel Bernard
*/
@ -22,35 +19,20 @@ public class Store {
private Integer id;
private String name;
private Set<KnownClient> customers;
private Set<Supplier> suppliers;
private Set<Item> items;
private Set<Category> categories;
@ManyToMany(cascade = CascadeType.PERSIST)
public Set<org.hibernate.test.annotations.manytomany.City> getImplantedIn() {
public Set<City> getImplantedIn() {
return implantedIn;
}
public void setImplantedIn(Set<org.hibernate.test.annotations.manytomany.City> implantedIn) {
public void setImplantedIn(Set<City> implantedIn) {
this.implantedIn = implantedIn;
}
private Set<City> implantedIn;
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinTable(
name = "StoreSupplier",
joinColumns = @JoinColumn(name = "store"),
inverseJoinColumns = @JoinColumn(name = "supplier")
)
public Set<Supplier> getSuppliers() {
return suppliers;
}
public void setSuppliers(Set<Supplier> suppliers) {
this.suppliers = suppliers;
}
@Id
@GeneratedValue
@Column(name="sId")