HHH-4679 Make sure @AssociationOverride support the dot notation. Package name change.
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18520 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
4224e74d1a
commit
87cf4555f6
|
@ -1,74 +0,0 @@
|
||||||
package org.hibernate.test.annotations.collectionelement;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.test.annotations.TestCase;
|
|
||||||
import org.hibernate.test.util.SchemaUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AssociationOverrideTest extends TestCase {
|
|
||||||
|
|
||||||
public void testDottedNotation() throws Exception {
|
|
||||||
assertTrue( SchemaUtil.isTablePresent( "Employee", getCfg() ) );
|
|
||||||
assertTrue( "Overridden @JoinColumn fails",
|
|
||||||
SchemaUtil.isColumnPresent( "Employee", "fld_address_fk", getCfg() ) );
|
|
||||||
|
|
||||||
assertTrue( "Overridden @JoinTable name fails", SchemaUtil.isTablePresent( "tbl_empl_sites", getCfg() ) );
|
|
||||||
assertTrue( "Overridden @JoinTable with default @JoinColumn fails",
|
|
||||||
SchemaUtil.isColumnPresent( "tbl_empl_sites", "employee_id", getCfg() ) );
|
|
||||||
assertTrue( "Overridden @JoinTable.inverseJoinColumn fails",
|
|
||||||
SchemaUtil.isColumnPresent( "tbl_empl_sites", "to_website_fk", getCfg() ) );
|
|
||||||
|
|
||||||
Session s = openSession();
|
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
ContactInfo ci = new ContactInfo();
|
|
||||||
Address address = new Address();
|
|
||||||
address.setCity("Boston");
|
|
||||||
address.setCountry("USA");
|
|
||||||
address.setState("MA");
|
|
||||||
address.setStreet("27 School Street");
|
|
||||||
address.setZipcode("02108");
|
|
||||||
ci.setAddress(address);
|
|
||||||
List<PhoneNumber> phoneNumbers = new ArrayList();
|
|
||||||
PhoneNumber num = new PhoneNumber();
|
|
||||||
num.setNumber(5577188);
|
|
||||||
Employee e = new Employee();
|
|
||||||
Collection employeeList = new ArrayList();
|
|
||||||
employeeList.add(e);
|
|
||||||
e.setContactInfo(ci);
|
|
||||||
num.setEmployees(employeeList);
|
|
||||||
phoneNumbers.add(num);
|
|
||||||
ci.setPhoneNumbers(phoneNumbers);
|
|
||||||
SocialTouchPoints socialPoints = new SocialTouchPoints();
|
|
||||||
List<SocialSite> sites = new ArrayList<SocialSite>();
|
|
||||||
SocialSite site = new SocialSite();
|
|
||||||
site.setEmployee(employeeList);
|
|
||||||
site.setWebsite("www.jboss.org");
|
|
||||||
sites.add(site);
|
|
||||||
socialPoints.setWebsite(sites);
|
|
||||||
ci.setSocial(socialPoints);
|
|
||||||
s.persist(e);
|
|
||||||
tx.commit();
|
|
||||||
|
|
||||||
tx = s.beginTransaction();
|
|
||||||
s.clear();
|
|
||||||
e = (Employee) s.get(Employee.class,e.getId());
|
|
||||||
tx.commit();
|
|
||||||
s.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Class[] getMappings() {
|
|
||||||
return new Class[] {
|
|
||||||
Employee.class,
|
|
||||||
PhoneNumber.class,
|
|
||||||
Address.class,
|
|
||||||
SocialSite.class,
|
|
||||||
SocialTouchPoints.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
package org.hibernate.test.annotations.collectionelement;
|
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.ManyToMany;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class PhoneNumber {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
int id;
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
int number;
|
|
||||||
|
|
||||||
@ManyToMany(mappedBy = "contactInfo.phoneNumbers", cascade = CascadeType.ALL)
|
|
||||||
Collection<Employee> employees;
|
|
||||||
|
|
||||||
public Collection<Employee> getEmployees() {
|
|
||||||
return employees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmployees(Collection<Employee> employees) {
|
|
||||||
this.employees = employees;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumber() {
|
|
||||||
return number;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNumber(int number) {
|
|
||||||
this.number = number;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +1,11 @@
|
||||||
package org.hibernate.test.annotations.collectionelement;
|
package org.hibernate.test.annotations.override;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Address {
|
public class Addr {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
int id;
|
int id;
|
|
@ -11,4 +11,29 @@ public class Address {
|
||||||
public String street;
|
public String street;
|
||||||
public String city;
|
public String city;
|
||||||
public String state;
|
public String state;
|
||||||
|
|
||||||
|
public String getCity() {
|
||||||
|
return city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCity(String city) {
|
||||||
|
this.city = city;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setState(String state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStreet() {
|
||||||
|
|
||||||
|
return street;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStreet(String street) {
|
||||||
|
this.street = street;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,11 @@ import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.test.annotations.TestCase;
|
import org.hibernate.test.annotations.TestCase;
|
||||||
|
import org.hibernate.test.util.SchemaUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
@ -37,11 +42,65 @@ public class AssociationOverrideTest extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDottedNotation() throws Exception {
|
||||||
|
assertTrue( SchemaUtil.isTablePresent( "Employee", getCfg() ) );
|
||||||
|
assertTrue( "Overridden @JoinColumn fails",
|
||||||
|
SchemaUtil.isColumnPresent( "Employee", "fld_address_fk", getCfg() ) );
|
||||||
|
|
||||||
|
assertTrue( "Overridden @JoinTable name fails", SchemaUtil.isTablePresent( "tbl_empl_sites", getCfg() ) );
|
||||||
|
assertTrue( "Overridden @JoinTable with default @JoinColumn fails",
|
||||||
|
SchemaUtil.isColumnPresent( "tbl_empl_sites", "employee_id", getCfg() ) );
|
||||||
|
assertTrue( "Overridden @JoinTable.inverseJoinColumn fails",
|
||||||
|
SchemaUtil.isColumnPresent( "tbl_empl_sites", "to_website_fk", getCfg() ) );
|
||||||
|
|
||||||
|
Session s = openSession();
|
||||||
|
Transaction tx = s.beginTransaction();
|
||||||
|
ContactInfo ci = new ContactInfo();
|
||||||
|
Addr address = new Addr();
|
||||||
|
address.setCity("Boston");
|
||||||
|
//address.setCountry("USA");
|
||||||
|
address.setState("MA");
|
||||||
|
address.setStreet("27 School Street");
|
||||||
|
//address.setZipcode("02108");
|
||||||
|
ci.setAddr(address);
|
||||||
|
List<PhoneNumber> phoneNumbers = new ArrayList();
|
||||||
|
PhoneNumber num = new PhoneNumber();
|
||||||
|
num.setNumber(5577188);
|
||||||
|
Employee e = new Employee();
|
||||||
|
Collection employeeList = new ArrayList();
|
||||||
|
employeeList.add(e);
|
||||||
|
e.setContactInfo(ci);
|
||||||
|
num.setEmployees(employeeList);
|
||||||
|
phoneNumbers.add(num);
|
||||||
|
ci.setPhoneNumbers(phoneNumbers);
|
||||||
|
SocialTouchPoints socialPoints = new SocialTouchPoints();
|
||||||
|
List<SocialSite> sites = new ArrayList<SocialSite>();
|
||||||
|
SocialSite site = new SocialSite();
|
||||||
|
site.setEmployee(employeeList);
|
||||||
|
site.setWebsite("www.jboss.org");
|
||||||
|
sites.add(site);
|
||||||
|
socialPoints.setWebsite(sites);
|
||||||
|
ci.setSocial(socialPoints);
|
||||||
|
s.persist(e);
|
||||||
|
tx.commit();
|
||||||
|
|
||||||
|
tx = s.beginTransaction();
|
||||||
|
s.clear();
|
||||||
|
e = (Employee) s.get(Employee.class,e.getId());
|
||||||
|
tx.commit();
|
||||||
|
s.close();
|
||||||
|
}
|
||||||
|
|
||||||
protected Class[] getMappings() {
|
protected Class[] getMappings() {
|
||||||
return new Class[]{
|
return new Class[]{
|
||||||
|
Employee.class,
|
||||||
Location.class,
|
Location.class,
|
||||||
Move.class,
|
Move.class,
|
||||||
Trip.class
|
Trip.class,
|
||||||
|
PhoneNumber.class,
|
||||||
|
Addr.class,
|
||||||
|
SocialSite.class,
|
||||||
|
SocialTouchPoints.class
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package org.hibernate.test.annotations.collectionelement;
|
package org.hibernate.test.annotations.override;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
import javax.persistence.Embedded;
|
import javax.persistence.Embedded;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.JoinTable;
|
|
||||||
import javax.persistence.ManyToMany;
|
import javax.persistence.ManyToMany;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -14,7 +13,7 @@ import java.util.List;
|
||||||
public class ContactInfo {
|
public class ContactInfo {
|
||||||
@ManyToOne(cascade = CascadeType.ALL)
|
@ManyToOne(cascade = CascadeType.ALL)
|
||||||
@JoinColumn(name="address_id_fk")
|
@JoinColumn(name="address_id_fk")
|
||||||
Address address;
|
Addr address;
|
||||||
|
|
||||||
@ManyToMany(cascade = CascadeType.ALL)
|
@ManyToMany(cascade = CascadeType.ALL)
|
||||||
List<PhoneNumber> phoneNumbers;
|
List<PhoneNumber> phoneNumbers;
|
||||||
|
@ -22,11 +21,11 @@ public class ContactInfo {
|
||||||
@Embedded
|
@Embedded
|
||||||
SocialTouchPoints social;
|
SocialTouchPoints social;
|
||||||
|
|
||||||
public Address getAddress() {
|
public Addr getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAddress(Address address) {
|
public void setAddr(Addr address) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.hibernate.test.annotations.collectionelement;
|
package org.hibernate.test.annotations.override;
|
||||||
|
|
||||||
import javax.persistence.AssociationOverride;
|
import javax.persistence.AssociationOverride;
|
||||||
import javax.persistence.AssociationOverrides;
|
import javax.persistence.AssociationOverrides;
|
|
@ -1,4 +1,4 @@
|
||||||
package org.hibernate.test.annotations.collectionelement;
|
package org.hibernate.test.annotations.override;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
|
@ -1,4 +1,6 @@
|
||||||
package org.hibernate.test.annotations.collectionelement;
|
package org.hibernate.test.annotations.override;
|
||||||
|
|
||||||
|
import org.hibernate.test.annotations.override.SocialSite;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
Loading…
Reference in New Issue