-->
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.  [ 1 post ] 
Author Message
 Post subject: Need help to query on one-many and many to one mapping
PostPosted: Mon Mar 12, 2012 1:50 pm 
Newbie

Joined: Mon Mar 12, 2012 1:38 pm
Posts: 4
HI ,

Im using the follwoing class Job.java
@Entity
@Table(name="WEB_UI_JOB")
public class Job implements Serializable {
@Id
@Column(name="JOB_ALIAS")
private String jobAlias;
@ManyToOne
@JoinColumn(name="SERVER_ALIAS")
private Server serverAlias;
@OneToMany(mappedBy="jobAlias")
private Set<JobFunction> webUiJobFunctionCollection;


and this is JobFunction.java

@ManyToOne
@JoinColumn(name="FUNCTION_ID" ,insertable=false, updatable=false)
private Function functionId;

@ManyToOne
@JoinColumn(name="JOB_ALIAS",insertable=false, updatable=false)
private Job jobAlias;

Im using the following query to search Job.class
public List<Job> search(String jobAlias, String serverAlias,String jobTitle){

Server server = null;
if (serverAlias != null) {
server = serverService.findById(serverAlias);

}

Session session = PersistenceSessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Job.class);

if (jobAlias != null) {
criteria.add(Restrictions.eq("jobAlias",jobAlias));
}
if (jobTitle != null) {
criteria.add(Restrictions.eq("jobTitle",jobTitle));
}

if (serverAlias != null) {
criteria.add(Restrictions.eq("serverAlias",server));
}


List<Job> jobList = criteria.list();

return jobList;

}

the above query is working fine.Which is used to return the list based on the input to the search.Now i need to refine the list returned by search based on the funcitonId in the JobFunction table also.
I need the search be modified with the new parameter added
public List<Job> search(String jobAlias, String serverAlias,String jobTitle,string functionID){

Server server = null;
if (serverAlias != null) {
server = serverService.findById(serverAlias);

}

Session session = PersistenceSessionFactory.getCurrentSession();
Criteria criteria = session.createCriteria(Job.class);

if (jobAlias != null) {
criteria.add(Restrictions.eq("jobAlias",jobAlias));
}
if (jobTitle != null) {
criteria.add(Restrictions.eq("jobTitle",jobTitle));
}

if (serverAlias != null) {
criteria.add(Restrictions.eq("serverAlias",server));
}


List<Job> jobList = criteria.list();

return jobList;

}



where functionID is searched based on JobAlias from job.java .

In the search function the parameter passed JobAlias may be null..but still the query should work retruning the list from Job.java

kindly help..thanks in advance


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.