From f8af94e559ef52c5940633ec5e6230fcafaf7cf2 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Thu, 11 Sep 2014 12:49:44 -0700 Subject: [PATCH] HHH-9390 : Default join column name (FK) for @ManyToMany uses owning entity primary table name (test cases) (cherry picked from commit d4d5fcc9e2386c14b4fd7d24b22bf26f25658df8) --- .../manytomany/defaults/Category.java | 2 -- .../annotations/manytomany/defaults/City.java | 2 -- .../manytomany/defaults/ContactInfo.java | 6 ++-- .../manytomany/defaults/Employee.java | 30 ------------------- .../annotations/manytomany/defaults/Item.java | 8 ++--- .../manytomany/defaults/KnownClient.java | 2 -- .../defaults/ManyToManyDefaultsTest.java | 21 ++++--------- .../manytomany/defaults/PhoneNumber.java | 6 ++-- .../manytomany/defaults/Store.java | 24 ++------------- 9 files changed, 16 insertions(+), 85 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Category.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Category.java index 9df506539b..65a1dd6951 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Category.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Category.java @@ -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 */ diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/City.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/City.java index 6ff26534c6..15aab3ecf9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/City.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/City.java @@ -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 */ diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ContactInfo.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ContactInfo.java index 34352f3ef4..cdd553fbf8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ContactInfo.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ContactInfo.java @@ -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 phoneNumbers; // Bidirectional + List phoneNumbers; // Bidirectional @ManyToMany(cascade= CascadeType.ALL) - public List getPhoneNumbers() { + public List getPhoneNumbers() { return phoneNumbers; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Employee.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Employee.java index d0dd4e547e..fddce4a4a5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Employee.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Employee.java @@ -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 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 getEmployers() { - return employers; - } - - public void setEmployers(Collection employers) { - this.employers = employers; - } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Item.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Item.java index c023e6ce7e..b9937e224a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Item.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Item.java @@ -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 producedInCities; + private Set producedInCities; @Id @GeneratedValue @@ -52,11 +50,11 @@ public class Item { } @ManyToMany - public Set getProducedInCities() { + public Set getProducedInCities() { return producedInCities; } - public void setProducedInCities(Set producedInCities) { + public void setProducedInCities(Set producedInCities) { this.producedInCities = producedInCities; } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/KnownClient.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/KnownClient.java index d3c42031d4..964335bc8f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/KnownClient.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/KnownClient.java @@ -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 */ diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyDefaultsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyDefaultsTest.java index f7ab329d6e..b1329c7dbc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyDefaultsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/ManyToManyDefaultsTest.java @@ -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 }; } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/PhoneNumber.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/PhoneNumber.java index fc36b73015..6ce1a75bba 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/PhoneNumber.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/PhoneNumber.java @@ -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 employees; + Collection employees; @Id public int getPhNumber() { @@ -22,7 +20,7 @@ public class PhoneNumber { } @ManyToMany(mappedBy="contactInfo.phoneNumbers", cascade= CascadeType.ALL) - public Collection getEmployees() { + public Collection getEmployees() { return employees; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Store.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Store.java index e7794ff696..2d6c3c7be4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Store.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/defaults/Store.java @@ -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 customers; - private Set suppliers; private Set items; private Set categories; @ManyToMany(cascade = CascadeType.PERSIST) - public Set getImplantedIn() { + public Set getImplantedIn() { return implantedIn; } - public void setImplantedIn(Set implantedIn) { + public void setImplantedIn(Set implantedIn) { this.implantedIn = implantedIn; } private Set implantedIn; - @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) - @JoinTable( - name = "StoreSupplier", - joinColumns = @JoinColumn(name = "store"), - inverseJoinColumns = @JoinColumn(name = "supplier") - ) - public Set getSuppliers() { - return suppliers; - } - - public void setSuppliers(Set suppliers) { - this.suppliers = suppliers; - } - @Id @GeneratedValue @Column(name="sId")