The scenario is i want to select candidates from my sql where resume searchable =1 and there city = Annistion. (resume searchable is in 1 table and city is in another table)
Code.
Criteria crit = session.createCriteria(CandidateResumeInfo.class);
Disjunction disc = Restrictions.disjunction();
crit.add(Restrictions.eq("resumeSearchable", 1));
crit.add(Restrictions.gt("lastUpdateDate",employerLastLoginDate));
crit.createCriteria("candidate")
.add(Restrictions.eq("userid",1));
//MatchedCvsAsyncDataProvider.setRowCount(count);
crit.setFirstResult(start);
crit.setMaxResults(length);
List rsList = crit.list();
// At this line my program crashes (if i remove the above line which says crit.createCriteria("candidate") .add(Restrictions.eq("userid",1)); // this its work fine )
for(Iterator it=rsList.iterator(); it.hasNext();)
{
candidateResumeInfo = (CandidateResumeInfo)it.next();
candidateResumeInfo.setRowCount(2);
allCandidateResumeInfo.add(candidateResumeInfo);
}
//session.close();
return allCandidateResumeInfo;
}
Here are my Two classes which i am joining
@Entity
@Table(name="candidateinfo")
public class CandidateInfo implements java.io.Serializable {
private int id;
private String firstName;
private String lastName;
private String city;
private String stateProvince;
private String zip;
private String country;
private String yearsOfExperience;
private String loginName;
private String password;
private String address;
private String emailAddress;
private int passwordResetQuestionId;
private String passwordResetAnswer;
private String middleName;
private String homeEveningPhone;
private String workDayPhone;
private boolean videoSubmited;
private boolean resumeSubmited;
private String cellPhone;
private String availability;
private String workStatus;
private String desiredSalary;
private String currentJobLevel;
private String currentJobTitle;
private String targetJobTitle;
private String alternateTargetJobTitle1;
private String alternateTargetJobTitle2;
private String targetJobType;
//private String eventType=null;
private String joinDate;
private String lastLoginDate;
@ManyToOne
CandidateResumeInfo candidate;
@Id
@GeneratedValue
@Column(name="userid")
public int getId() {
return this.id;
}
@Column(name="loginname")
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
@Column(name="password")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name="address")
public String getAddress() {
return address;
}
This is the other Class
@Entity
@Table(name="candidateresumeinfo")
public class CandidateResumeInfo implements Serializable{
private int resumeId;
private int candidate_userId;
private String resumeFileLocation;
private int resumeSearchable;
private Date lastUpdateDate;
private String resumeTitle;
private String resumeText;
private String skills;
private int rowCount;
@Column(name="resumeSearchable")
public int isResumeSearchable() {
return resumeSearchable;
}
public void setResumeSearchable(int resumeSearchable) {
this.resumeSearchable = resumeSearchable;
}
@Id
@GeneratedValue
@Column(name="resumeid")
public int getResumeId() {
return resumeId;
}
public void setResumeId(int resumeId) {
this.resumeId = resumeId;
}
@Column(name="candidate_userid")
public int getCandidate_userId() {
return candidate_userId;
}
public void setCandidate_userId(int candidate_userId) {
this.candidate_userId = candidate_userId;
}
@Column(name="resumelocation")
public String getResumeFileLocation() {
return resumeFileLocation;
}
public void setResumeFileLocation(String resumeFileLocation) {
this.resumeFileLocation = resumeFileLocation;
}
/*
public boolean isResumeDisclosure() {
return resumeSearchable;
}
public void setResumeDisclosure(boolean resumeDisclosure) {
this.resumeSearchable = resumeDisclosure;
}*/
@Column(name="resumetitle")
public String getResumeTitle() {
return resumeTitle;
}
public void setResumeTitle(String resumeTitle) {
this.resumeTitle = resumeTitle;
}
@Column(name="resumetext")
public String getResumeText() {
return resumeText;
}
public void setResumeText(String resumeText) {
this.resumeText = resumeText;
}
public void setLastUpdateDate(Date lastUpdateDate) {
this.lastUpdateDate = lastUpdateDate;
}
@Column(name="lastUpdateDate")
public Date getLastUpdateDate() {
return lastUpdateDate;
}
This is my Applicantioncontext.xml file
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
default-lazy-init="true">
<!-- Datasource for database connection -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url"
value="jdbc:mysql://localhost:3306/jobsite" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.zrsol.joblistings.shared.Employer</value>
<value>com.zrsol.joblistings.shared.StatesProvinces</value>
<value>com.zrsol.joblistings.shared.EmployerJobs</value>
<value>com.zrsol.joblistings.shared.CandidateResumeInfo</value>
<value>com.zrsol.joblistings.shared.CandidateSkills</value>
<value>com.zrsol.joblistings.shared.CandidateInfo</value>
</list>
</property>
</bean>
<bean id ="ManagerJobs" class= "jobsite.persistence.MySQLRdbSpringHelper">
< property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
Here is the Stack Trace 01:41:57,623 INFO SessionFactoryObjectFactory:105 - Not binding factory to JNDI, no JNDI name configured 01:41:57,624 DEBUG SessionFactoryImpl:340 - instantiated session factory 01:41:57,625 DEBUG SessionFactoryImpl:426 - Checking 0 named HQL queries 01:41:57,626 DEBUG SessionFactoryImpl:446 - Checking 0 named SQL queries 01:41:57,626 DEBUG DefaultListableBeanFactory:411 - Finished creating instance of bean 'sessionFactory' 01:41:57,627 DEBUG DefaultListableBeanFactory:411 - Finished creating instance of bean 'ManagerJobs' 01:41:57,629 DEBUG SessionImpl:247 - opened session at timestamp: 13066477176 01:41:57,631 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0) 01:41:57,631 DEBUG ConnectionManager:444 - opening JDBC connection 01:41:57,632 DEBUG DriverManagerDataSource:163 - Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost:3306/jobsite] 01:41:57,667 DEBUG SQL:111 - select this_.lastLoginDate as y0_ from employerinfo this_ where this_.companyid=? 01:41:57,667 DEBUG SQL:111 - select this_.lastLoginDate as y0_ from employerinfo this_ where this_.companyid=? 01:41:57,669 DEBUG AbstractBatcher:426 - about to open ResultSet (open ResultSets: 0, globally: 0) 01:41:57,669 DEBUG Loader:1197 - result row: 01:41:57,670 DEBUG AbstractBatcher:433 - about to close ResultSet (open ResultSets: 1, globally: 1) 01:41:57,670 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1) 01:41:57,671 DEBUG StatefulPersistenceContext:860 - initializing non-lazy collections 01:41:57,671 DEBUG ConnectionManager:325 - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!