HHH-4679 Make sure @AssociationOverride support the dot notation

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18515 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Scott Marlow 2010-01-12 16:03:48 +00:00
parent 6015123700
commit d5f9bd5377
7 changed files with 341 additions and 0 deletions

View File

@ -0,0 +1,67 @@
package org.hibernate.test.annotations.collectionelement;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class Address {
@Id
int id;
private String street;
private String city;
private String state;
private String country;
private String zipcode;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
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 getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getZipcode() {
return zipcode;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}

View File

@ -0,0 +1,63 @@
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 java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class AssociationOverrideTest extends TestCase {
public void testDottedNotation() throws Exception {
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
};
}
}

View File

@ -0,0 +1,46 @@
package org.hibernate.test.annotations.collectionelement;
import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import java.util.List;
@Embeddable
public class ContactInfo {
@ManyToOne(targetEntity=Address.class, cascade=CascadeType.ALL)
Address address;
@ManyToMany(targetEntity=PhoneNumber.class, cascade=CascadeType.ALL)
List<PhoneNumber> phoneNumbers;
@Embedded
SocialTouchPoints social;
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public List<PhoneNumber> getPhoneNumbers() {
return phoneNumbers;
}
public void setPhoneNumbers(List<PhoneNumber> phoneNumbers) {
this.phoneNumbers = phoneNumbers;
}
public SocialTouchPoints getSocial() {
return social;
}
public void setSocial(SocialTouchPoints social) {
this.social = social;
}
}

View File

@ -0,0 +1,58 @@
package org.hibernate.test.annotations.collectionelement;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
@Entity
public class Employee {
@Id
int id;
/* @AssociationOverride(
name="social.website",
joinTable=@JoinTable(
name="xxxwebsites",
joinColumns=@JoinColumn(name="id"),
inverseJoinColumns=@JoinColumn(name="id" )
)
)
@AssociationOverride(
name="social.website",
joinColumns=@JoinColumn(name="id"))
*/
@AssociationOverride(
name="social.website",
joinTable=@JoinTable(
name="xxxwebsites",
joinColumns=@JoinColumn(name=""),
inverseJoinColumns=@JoinColumn(name="id" )
)
)
@Embedded
ContactInfo contactInfo;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public ContactInfo getContactInfo() {
return contactInfo;
}
public void setContactInfo(ContactInfo contactInfo) {
this.contactInfo = contactInfo;
}
}

View File

@ -0,0 +1,43 @@
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;
}
}

View File

@ -0,0 +1,42 @@
package org.hibernate.test.annotations.collectionelement;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import java.util.Collection;
@Entity
public class SocialSite {
@Id
int id;
String website;
@ManyToMany(mappedBy="contactInfo.social.website")
Collection<Employee> employee;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
public Collection<Employee> getEmployee() {
return employee;
}
public void setEmployee(Collection<Employee> employee) {
this.employee = employee;
}
}

View File

@ -0,0 +1,22 @@
package org.hibernate.test.annotations.collectionelement;
import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.ManyToMany;
import java.util.List;
@Embeddable
public class SocialTouchPoints {
// owning side of many to many
@ManyToMany(targetEntity=SocialSite.class, cascade= CascadeType.ALL)
List<SocialSite> website;
public List<SocialSite> getWebsite() {
return website;
}
public void setWebsite(List<SocialSite> website) {
this.website = website;
}
}