|
|
Re: 3 table cascade reference @JoinFetch [message #1061324 is a reply to message #1061251] |
Fri, 31 May 2013 08:31 |
alex alex Messages: 3 Registered: May 2013 |
Junior Member |
|
|
thanks for answer,
I have tried with @BatchFetch too but I have had less results,maybe I have make some mistake.
here's the generated query asking for find() on Entity A and the class code in @JoinFetch
SELECT DISTINCT t1.ID, t1.BUSINESS_NAME, t0.ID, t0.FIRST_NAME, t0.EMPLOYER_ID FROM employees t0, employers t1 WHERE ((t1.ID = ?) AND (t0.EMPLOYER_ID = t1.ID))
...ad you can see the Benefits table (Entity C ) as not been included in query
I'd want all the 3 entity in Join in one query....so I can make performance stress test to decide framework policy
Then I can try with @BatchJoin too for performance test.
Thanks for help!!
here's the code:
Class EMPLOYERS ( Entity A )
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.eclipse.persistence.annotations.BatchFetch;
import org.eclipse.persistence.annotations.BatchFetchType;
import org.eclipse.persistence.annotations.JoinFetch;
import org.eclipse.persistence.annotations.JoinFetchType;
@Entity
@Table(name = "employers")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Employers.findAll", query = "SELECT e FROM Employers e"),
@NamedQuery(name = "Employers.findById", query = "SELECT e FROM Employers e WHERE e.id = :id"),
@NamedQuery(name = "Employers.findByBusinessName", query = "SELECT e FROM Employers e WHERE e.businessName = :businessName")})
public class Employers implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "ID")
private Long id;
@Size(max = 128)
@Column(name = "BUSINESS_NAME")
private String businessName;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "employerId", fetch = FetchType.LAZY)
@JoinFetch(JoinFetchType.INNER)
//@BatchFetch(BatchFetchType.JOIN)
private List<Employees> employeesList;
public Employers() {
}
public Employers(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getBusinessName() {
return businessName;
}
public void setBusinessName(String businessName) {
this.businessName = businessName;
}
@XmlTransient
public List<Employees> getEmployeesList() {
return employeesList;
}
public void setEmployeesList(List<Employees> employeesList) {
this.employeesList = employeesList;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Employers)) {
return false;
}
Employers other = (Employers) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "test.jpaperformance.entity.Employers[ id=" + id + " ]";
}
}
EMPLOYEES ( Entity B )
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.eclipse.persistence.annotations.BatchFetch;
import org.eclipse.persistence.annotations.BatchFetchType;
import org.eclipse.persistence.annotations.JoinFetch;
import org.eclipse.persistence.annotations.JoinFetchType;
@Entity
@Table(name = "employees")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Employees.findAll", query = "SELECT e FROM Employees e"),
@NamedQuery(name = "Employees.findById", query = "SELECT e FROM Employees e WHERE e.id = :id"),
@NamedQuery(name = "Employees.findByFirstName", query = "SELECT e FROM Employees e WHERE e.firstName = :firstName")})
public class Employees implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "ID")
private Long id;
@Size(max = 64)
@Column(name = "FIRST_NAME")
private String firstName;
@JoinFetch(JoinFetchType.OUTER)
//@BatchFetch(BatchFetchType.JOIN)
@OneToMany(cascade = CascadeType.ALL, mappedBy = "employeeId", fetch = FetchType.LAZY)
private List<Benefits> benefitsList;
@JoinColumn(name = "EMPLOYER_ID", referencedColumnName = "ID")
@JoinFetch(JoinFetchType.INNER)
//@BatchFetch(BatchFetchType.JOIN)
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private Employers employerId;
public Employees() {
}
public Employees(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
@XmlTransient
public List<Benefits> getBenefitsList() {
return benefitsList;
}
public void setBenefitsList(List<Benefits> benefitsList) {
this.benefitsList = benefitsList;
}
public Employers getEmployerId() {
return employerId;
}
public void setEmployerId(Employers employerId) {
this.employerId = employerId;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Employees)) {
return false;
}
Employees other = (Employees) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "test.jpaperformance.entity.Employees[ id=" + id + " ]";
}
}
BENEFITS ( Entity C )
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.persistence.annotations.BatchFetch;
import org.eclipse.persistence.annotations.BatchFetchType;
import org.eclipse.persistence.annotations.JoinFetch;
import org.eclipse.persistence.annotations.JoinFetchType;
@Entity
@Table(name = "benefits")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Benefits.findAll", query = "SELECT b FROM Benefits b"),
@NamedQuery(name = "Benefits.findById", query = "SELECT b FROM Benefits b WHERE b.id = :id"),
@NamedQuery(name = "Benefits.findByBenefitType", query = "SELECT b FROM Benefits b WHERE b.benefitType = :benefitType"),
@NamedQuery(name = "Benefits.findByStartDate", query = "SELECT b FROM Benefits b WHERE b.startDate = :startDate"),
@NamedQuery(name = "Benefits.findByEndDate", query = "SELECT b FROM Benefits b WHERE b.endDate = :endDate"),
@NamedQuery(name = "Benefits.findByName", query = "SELECT b FROM Benefits b WHERE b.name = :name")})
public class Benefits implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "ID")
private Long id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 64)
@Column(name = "BENEFIT_TYPE")
private String benefitType;
@Column(name = "START_DATE")
@Temporal(TemporalType.DATE)
private Date startDate;
@Column(name = "END_DATE")
@Temporal(TemporalType.DATE)
private Date endDate;
@Size(max = 128)
@Column(name = "NAME")
private String name;
@JoinColumn(name = "EMPLOYEE_ID", referencedColumnName = "ID")
@JoinFetch(JoinFetchType.INNER)
//@BatchFetch(BatchFetchType.JOIN)
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private Employees employeeId;
public Benefits() {
}
public Benefits(Long id) {
this.id = id;
}
public Benefits(Long id, String benefitType) {
this.id = id;
this.benefitType = benefitType;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getBenefitType() {
return benefitType;
}
public void setBenefitType(String benefitType) {
this.benefitType = benefitType;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Employees getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Employees employeeId) {
this.employeeId = employeeId;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Benefits)) {
return false;
}
Benefits other = (Benefits) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "test.jpaperformance.entity.Benefits[ id=" + id + " ]";
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04937 seconds