-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: 3 Lists fetching in the same table with 3 differents filters
PostPosted: Wed Mar 16, 2011 7:37 pm 
Newbie

Joined: Wed Mar 16, 2011 7:29 pm
Posts: 1
Hi there, i'm glad to join this magnificent community! This is my first big problem i'm getting
and i hope that you cian help me out!!!!!

I'm trying to fetch eagerly in 3 LISTS with each having one filter to filter out the specified flag.
When i get the result all 3 of these lists populate the same stuff. The filtering doesn't work and
i don't know if hibernate allows me to do that kind of operation in fact.

Here is my code for the ENTITY

@Entity
@Table(name = "users")
@FilterDefs({
@FilterDef(name="filter_by_profile_experiences", parameters={@ParamDef(name="item_type1",type="string")}, defaultCondition="itemType LIKE \"EXP\""),
@FilterDef(name="filter_by_profile_certifications", parameters={@ParamDef(name="item_type2",type="string")}, defaultCondition="itemType LIKE \"CER\""),
@FilterDef(name="filter_by_profile_diplomas", parameters={@ParamDef(name="item_type3",type="string")}, defaultCondition="itemType LIKE \"DIP\"")
})
public class User implements Serializable {

private static final long serialVersionUID = 1L;

@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
@IndexColumn(name = "INDEX_COL")
@NotFound(action = NotFoundAction.IGNORE)
//@LazyCollection(LazyCollectionOption.FALSE)
private List<Meeting> meetings = new ArrayList<Meeting>();

@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
@IndexColumn(name = "INDEX_COL")
@NotFound(action = NotFoundAction.IGNORE)
//@LazyCollection(LazyCollectionOption.FALSE)
private List<JobApplicationParsed> jobApplications = new ArrayList<JobApplicationParsed>();

/*
@OneToMany(fetch = FetchType.EAGER)
//@JoinTable
@JoinColumn(name = "user_id")
@IndexColumn(name = "INDEX_COL")
@NotFound(action = NotFoundAction.IGNORE)
//@LazyCollection(LazyCollectionOption.FALSE)
private List<JobApplication> acceptedJobApplications = new ArrayList<JobApplication>();

@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
@IndexColumn(name = "INDEX_COL")
@NotFound(action = NotFoundAction.IGNORE)
//@LazyCollection(LazyCollectionOption.FALSE)
private List<ProfileEntry> profileEntries = new ArrayList<ProfileEntry>();
*/

@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
@IndexColumn(name = "INDEX_COL")
@NotFound(action = NotFoundAction.IGNORE)
@Filter(name="filter_by_profile_experiences", condition="itemType LIKE \":item_type1\"")
private List<ProfileEntry> profileExperiences;

@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
@IndexColumn(name = "INDEX_COL")
@NotFound(action = NotFoundAction.IGNORE)
@Filter(name="filter_by_profile_certifications", condition="itemType LIKE \":item_type2\"")
private List<ProfileEntry> profileCertifications;

@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "user_id")
@IndexColumn(name = "INDEX_COL")
@NotFound(action = NotFoundAction.IGNORE)
@Filter(name="filter_by_profile_diplomas", condition="itemType LIKE \":item_type3\"")
private List<ProfileEntry> profileDiplomas;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "id")
@NotFound(action = NotFoundAction.IGNORE)
private Template template;

@Id
@Column(name = "id", updatable = false, nullable = false)
@GeneratedValue
private long id;

@Column(name = "username", length = 128, nullable = false, unique = true)
private String username;

@Column(name = "password", nullable = false)
private String password;

@Column(name = "first_name", nullable = true)
private String first_name;

@Column(name = "last_name", nullable = true)
private String last_name;

@Column(name = "birth_date", nullable = true)
private Date birth_date;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "country_id", updatable=true, insertable=true)
@NotFound(action = NotFoundAction.IGNORE)
private VariableValueParsed country;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "state_id", updatable=true, insertable=true)
@NotFound(action = NotFoundAction.IGNORE)
private VariableValueParsed state;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "city_id", updatable=true, insertable=true)
@NotFound(action = NotFoundAction.IGNORE)
private VariableValueParsed city;

/*
@Column(name = "country_id", nullable = false)
private int country_id;

@Column(name = "state_id", nullable = false)
private int state_id;

@Column(name = "city_id", nullable = false)
private int city_id;
*/

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "industry_id", updatable=true, insertable=false)
@NotFound(action = NotFoundAction.IGNORE)
private VariableValueParsed industry;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "category_id", updatable=true, insertable=false)
@NotFound(action = NotFoundAction.IGNORE)
private VariableValueParsed category;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "subcategory_id", updatable=true, insertable=false)
@NotFound(action = NotFoundAction.IGNORE)
private VariableValueParsed subcategory;

/*
@Column(name = "industry_id", nullable = false)
private long industry_id;

@Column(name = "category_id", nullable = false)
private long category_id;

@Column(name = "subcategory_id", nullable = false)
private long subcategory_id;
*/

@Column(name = "email", length = 255, nullable = false, unique = true)
private String email;

@Column(name = "address", nullable = true)
private String address;

@Column(name = "postal_code", nullable = true)
private String postalCode;

@Column(name = "home_number", nullable = true)
private String homeNumber;

@Column(name = "cell_number", nullable = true)
private String cellNumber;

@Column(name = "work_number", nullable = true)
private String workNumber;

@Column(name = "fax_number", nullable = true)
private String faxNumber;

@Column(name = "linkedin", nullable = true)
private String linkedin;

@Column(name = "twitter", nullable = true)
private String twitter;

@Column(name = "facebook", nullable = true)
private String facebook;

@Column(name = "web_site", nullable = true)
private String website;

@Column(name = "blog", nullable = true)
private String blog;

@Column(name = "profile_video", nullable = true)
private String profileVideo;

@Column(name = "profile_picture", nullable = true)
private String profilePicture;

@Column(name = "profile_resume", nullable = true)
private String profileResume;

@Column(name = "job_category_id", nullable = true)
private String jobCategoryId;

@Column(name = "active", nullable = false)
private boolean active;

@Column(name = "registered", nullable = false)
private boolean registered;

@Column(name = "session_id", nullable = true)
private String sessionId;

@Column(name = "skills_tags", nullable = true)
private String skillsTags;

@Column(name = "send_sms", nullable = false)
private boolean sendSms;

@Column(name = "sms_provider_id", nullable = true)
private long smsProviderId;

@Column(name = "male", nullable = false)
private boolean male;

@Transient
private String r5Id;

@Transient
private String base64Picture;

public String getSessionId() {
return sessionId;
}

public void setSessionId(String session_id) {
this.sessionId = session_id;
}

public String getEmail() {
return email;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getLinkedin() {
return linkedin;
}

public void setLinkedin(String linkedin) {
this.linkedin = linkedin;
}

public String getTwitter() {
return twitter;
}

public void setTwitter(String twitter) {
this.twitter = twitter;
}

public String getFacebook() {
return facebook;
}

public void setFacebook(String facebook) {
this.facebook = facebook;
}

public String getWebsite() {
return website;
}

public void setWebsite(String website) {
this.website = website;
}

public String getBlog() {
return blog;
}

public void setBlog(String blog) {
this.blog = blog;
}

public boolean getActive() {
return active;
}

public void setActive(boolean active) {
this.active = active;
}

public boolean getRegistered() {
return registered;
}

public void setRegistered(boolean registered) {
this.registered = registered;
}

public void setEmail(String email) {
this.email = email;
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public Date getBirthDate() {
return birth_date;
}

public void setBirthDate(Date birth_date) {
this.birth_date = birth_date;
}

public String getFirstName() {
return first_name;
}

public void setFirstName(String first_name) {
this.first_name = first_name;
}

public String getLastName() {
return last_name;
}

public void setLastName(String last_name) {
this.last_name = last_name;
}

public VariableValueParsed getCountry() {
return country;
}

public void setCountry(VariableValueParsed country) {
this.country = country;
}

public VariableValueParsed getState() {
return state;
}

public void setState(VariableValueParsed state) {
this.state = state;
}

public VariableValueParsed getCity() {
return city;
}

public void setCity(VariableValueParsed city) {
this.city = city;
}

public VariableValueParsed getIndustry() {
return industry;
}

public void setIndustry(VariableValueParsed industry) {
this.industry = industry;
}

public VariableValueParsed getCategory() {
return category;
}

public void setCategory(VariableValueParsed category) {
this.category = category;
}

public VariableValueParsed getSubcategory() {
return subcategory;
}

public void setSubcategory(VariableValueParsed subcategory) {
this.subcategory = subcategory;
}
/*
public int getCountryId() {
return country_id;
}

public void setCountryId(int country_id) {
this.country_id = country_id;
}

public int getStateId() {
return state_id;
}

public void setStateId(int state_id) {
this.state_id = state_id;
}

public int getCityId() {
return city_id;
}

public void setCityId(int city_id) {
this.city_id = city_id;
}

public long getIndustryId() {
return industry_id;
}

public void setIndustryId(long industry_id) {
this.industry_id = industry_id;
}

public long getCategoryId() {
return category_id;
}

public void setCategoryId(long category_id) {
this.category_id = category_id;
}

public long getSubcategoryId() {
return subcategory_id;
}

public void setSubcategoryId(long subcategory_id) {
this.subcategory_id = subcategory_id;
}

*/
public String getR5Id() {
return r5Id;
}

public void setR5Id(String r5Id) {
this.r5Id = r5Id;
}

public String getProfileVideo() {
return profileVideo;
}

public String getProfilePicture() {
return profilePicture;
}

public String getProfileResume() {
return profileResume;
}

public void setProfileVideo(String profileVideo) {
this.profileVideo = profileVideo;
}

public void setProfilePicture(String profilePicture) {
this.profilePicture = profilePicture;
}

public void setProfileResume(String profileResume) {
this.profileResume = profileResume;
}

public String getPostalCode() {
return postalCode;
}

public String getHomeNumber() {
return homeNumber;
}

public String getCellNumber() {
return cellNumber;
}

public String getFaxNumber() {
return faxNumber;
}

public String getJobCategoryId() {
return jobCategoryId;
}

public String getSkillsTags() {
return skillsTags;
}

public boolean isSendSms() {
return sendSms;
}

public long getSmsProviderId() {
return smsProviderId;
}

public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}

public void setHomeNumber(String homeNumber) {
this.homeNumber = homeNumber;
}

public void setCellNumber(String cellNumber) {
this.cellNumber = cellNumber;
}

public void setFaxNumber(String faxNumber) {
this.faxNumber = faxNumber;
}

public void setJobCategoryId(String jobCategoryId) {
this.jobCategoryId = jobCategoryId;
}

public void setSkillsTags(String skillsTags) {
this.skillsTags = skillsTags;
}

public void setSendSms(boolean sendSms) {
this.sendSms = sendSms;
}

public void setSmsProviderId(long smsProviderId) {
this.smsProviderId = smsProviderId;
}

public String getBase64Picture() {
return base64Picture;
}

public void setBase64Picture(String base64Picture) {
this.base64Picture = base64Picture;
}

/*
@Transient
public List<JobApplication> getAcceptedJobApplications() {
ArrayCollection<JobApplication> result = new ArrayCollection<JobApplication>();
if (this.jobApplications != null && this.jobApplications.size() > 0) {
for (JobApplication jobApp : this.jobApplications) {
if (jobApp.getAccepted())
result.add(jobApp);
}
}
return result;
}*/

/*
public List<ProfileEntry> getProfileEntries() {
return profileEntries;
}

public void setProfileEntries(List<ProfileEntry> profileEntries) {
this.profileEntries = profileEntries;
}*/

public Template getTemplate() {
return template;
}

public void setTemplate(Template template) {
this.template = template;
}

public String getWorkNumber() {
return workNumber;
}

public void setWorkNumber(String workNumber) {
this.workNumber = workNumber;
}

public boolean isMale() {
return male;
}

public void setMale(boolean male) {
this.male = male;
}

@Transient
public UserParsed toUserParsed(){
UserParsed result = new UserParsed();
result.setFirstName(this.getFirstName());
result.setLastName(this.getLastName());
result.setId(this.getId());
return result;
}

public List<Meeting> getMeetings() {
return meetings;
}

public void setMeetings(List<Meeting> meetings) {
this.meetings = meetings;
}

public List<JobApplicationParsed> getJobApplications() {
return jobApplications;
}

public void setJobApplications(List<JobApplicationParsed> jobApplications) {
this.jobApplications = jobApplications;
}

/*
public List<JobApplication> getAcceptedJobApplications(){
return this.acceptedJobApplications;
}
public void setAcceptedJobApplications(List<JobApplication> acceptedJobApplications) {
this.acceptedJobApplications = acceptedJobApplications;
}
*/

public List<ProfileEntry> getProfileExperiences() {
return profileExperiences;
}

public List<ProfileEntry> getProfileCertifications() {
return profileCertifications;
}

public List<ProfileEntry> getProfileDiplomas() {
return profileDiplomas;
}

public void setProfileExperiences(List<ProfileEntry> profileExperiences) {
this.profileExperiences = profileExperiences;
}

public void setProfileCertifications(List<ProfileEntry> profileCertifications) {
this.profileCertifications = profileCertifications;
}

public void setProfileDiplomas(List<ProfileEntry> profileDiplomas) {
this.profileDiplomas = profileDiplomas;
}

}

HERE IS THE DAO ENABLING THE FILTERS

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public User getUserByUsername(String username) {
User user = null;

Transaction tx = hibernateTemplate.getSessionFactory().getCurrentSession().beginTransaction();
Session session = hibernateTemplate.getSessionFactory().getCurrentSession();
tx.begin();
session.enableFilter("filter_by_profile_experiences").setParameter("item_type1", "EXP");
session.enableFilter("filter_by_profile_certifications").setParameter("item_type2", "CER");
session.enableFilter("filter_by_profile_diplomas").setParameter("item_type3", "DIP");
List<User> result = hibernateTemplate.find("from User where username = ?", username);

if (result.size() == 1)
user = result.get(0);

session.disableFilter("filter_by_profile_experiences");
session.disableFilter("filter_by_profile_certifications");
session.disableFilter("filter_by_profile_diplomas");
tx.commit();
return user;
}

The fetching works great but the 3 lists are not well populated!


Top
 Profile  
 
 Post subject: Re: 3 Lists fetching in the same table with 3 differents filters
PostPosted: Thu Mar 17, 2011 4:55 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Why do you use parameters at all, if these always have the same value? Have a look at @Where, this looks more appropriate for you.

btw. use the code-tag to post code. [code] [/code]

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.