I have two classes Customer and Merchant with many-to-many relationship as shown below.
Code:
public class Customer implements Serializable {
private Collection<Merchant> preferences;
@ManyToMany(targetEntity = Merchant.class, cascade = { CascadeType.PERSIST,
CascadeType.MERGE, CascadeType.ALL }, fetch = FetchType.EAGER)
@JoinTable(name = "CUSTOMER_MERCHANT", joinColumns = @JoinColumn(name = "CUSTOMER_ID"), inverseJoinColumns = @JoinColumn(name = "MERCHANT_ID"))
public Collection<Merchant> getPreferences() {
return preferences;
}
public void setPreferences(Collection<Merchant> preferences) {
this.preferences = preferences;
}
}
Code:
public class Merchant implements Serializable {
private Collection<Customer> cutomers;
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
CascadeType.ALL }, fetch = FetchType.EAGER, mappedBy = "preferences", targetEntity = Customer.class)
public Collection<Customer> getCutomers() {
return cutomers;
}
public void setCutomers(Collection<Customer> cutomers) {
this.cutomers = cutomers;
}
}
I need to get the merchants according to the customer's preferences using hibernate template. since my DAO class extends HibernateDaoSupport, i need a solution based on it. Please help me.........