添加两个不同的表是一个单一的标准(加入)

时间:2011-05-29 07:01:33

标签: hibernate

场景是我想从我的sql中选择resume searchable = 1并且city = Annistion。 (恢复搜索在1表中,城市在另一个表中)

代码。

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();

//在这一行我的程序崩溃了(如果我删除上面的行,表示crit.createCriteria(“候选人”)             。新增(Restrictions.eq( “参数userid”,1)); //这个工作正常)

for(Iterator it=rsList.iterator(); it.hasNext();)

    {
        candidateResumeInfo = (CandidateResumeInfo)it.next();
        candidateResumeInfo.setRowCount(2);
        allCandidateResumeInfo.add(candidateResumeInfo);

    }
    //session.close();
    return allCandidateResumeInfo;
}

以下是我加入的两个班级

     @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;
}

这是另一个班级

      @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;
}

这是我的Applicantioncontext.xml文件

             <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>

这是Stack Trace 01:41:57,623 INFO SessionFactoryObjectFactory:105 - 未将工厂绑定到JNDI,未配置JNDI名称 01:41:57,624 DEBUG SessionFactoryImpl:340 - 实例化会话工厂 01:41:57,625 DEBUG SessionFactoryImpl:426 - 检查0个名为HQL的查询 01:41:57,626 DEBUG SessionFactoryImpl:446 - 检查0个命名的SQL查询 01:41:57,626 DEBUG DefaultListableBeanFactory:411 - 完成创建bean'sessionFactory'的实例 01:41:57,627 DEBUG DefaultListableBeanFactory:411 - 完成创建bean'ManagerJobs'的实例 01:41:57,629 DEBUG SessionImpl:247 - 时间戳开放时间:13066477176 01:41:57,631 DEBUG AbstractBatcher:410 - 即将打开PreparedStatement(打开PreparedStatements:0,全局:0) 01:41:57,631 DEBUG ConnectionManager:444 - 打开JDBC连接 01:41:57,632 DEBUG DriverManagerDataSource:163 - 创建新的JDBC DriverManager连接到[jdbc:mysql:// localhost:3306 / jobsite] 01:41:57,667 DEBUG SQL:111 - 从employerinfo this_中选择this_.lastLoginDate为y0_,其中this_.companyid =? 01:41:57,667 DEBUG SQL:111 - 从employerinfo this_中选择this_.lastLoginDate为y0_,其中this_.companyid =? 01:41:57,669 DEBUG AbstractBatcher:426 - 即将打开ResultSet(打开ResultSet:0,全局:0) 01:41:57,669 DEBUG Loader:1197 - 结果行: 01:41:57,670 DEBUG AbstractBatcher:433 - 即将关闭ResultSet(打开ResultSet:1,全局:1) 01:41:57,670 DEBUG AbstractBatcher:418 - 即将关闭PreparedStatement(打开PreparedStatements:1,全局:1) 01:41:57,671 DEBUG StatefulPersistenceContext:860 - 初始化非惰性集合 01:41:57,671 DEBUG ConnectionManager:325 - 在on_close连接释放模式的会话中完成的事务;一定要关闭会话以释放JDBC资源!

0 个答案:

没有答案