想要在一个休眠条件中添加两个不同的表(类)

发布于 2024-11-10 08:53:01 字数 4996 浏览 4 评论 0原文

我有这段代码

ArrayList<String> city = 'Anniston';

Criteria  crit = session.createCriteria(CandidateResumeInfo.class);
 crit.add(Restrictions.eq("resumeSearchable", 1));

现在我想添加以下条件

crit.add(Restrictions.in("cities", city));

但问题是城市列不在 CandidateResumeInfo.class 中 它在 CandidateInfo 类中。

知道如何在上述条件中添加此条件,如何在上述条件中添加 CandidateInfo 类。

我猜我需要连接或链接这两个表,但是如何连接或链接实体类,以及实体类是否会有任何变化?

这是我的两堂课

@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 Set candidateVideos = new HashSet();

    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=null;
    private String workStatus=null;

    private String desiredSalary=null;
    private String currentJobLevel=null;
    private String currentJobTitle=null;
    private String targetJobTitle=null;
    private String alternateTargetJobTitle1=null;
    private String alternateTargetJobTitle2=null;
    private String targetJobType=null;
    private String eventType=null;

    private String joinDate = null;
    private String lastLoginDate = null;

    //private SkillsBean skillsInfo;
    private Set skills = new HashSet();
    private Set candidateResumes = new HashSet();
    private Set targetJobCategoriesId = new HashSet();
    private Set targetJobLocationsId = new HashSet();


    public CandidateInfo() {
    }
    @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;
    }

    public void setAddress(String address) {
        this.address = 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;
    }

    @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;
    }
    @Column(name="skills")
    public String getSkills() {
        return skills;
    }

    public void setSkills(String skills) {
        this.skills = skills;
    }
    @Transient
    public int getRowCount() {
        return rowCount;
    }

    public void setRowCount(int count) {
        this.rowCount = count;
    }

I have this code

ArrayList<String> city = 'Anniston';

Criteria  crit = session.createCriteria(CandidateResumeInfo.class);
 crit.add(Restrictions.eq("resumeSearchable", 1));

Now I want to add below criteria

crit.add(Restrictions.in("cities", city));

but the problem is that cities column is not in CandidateResumeInfo.class its in CandidateInfo Class.

Any idea how to add this criteria as well in the above one,how to add CandidateInfo class as well in the above criteria.

guess i need to do join or link these two tables but how, and will there be any changes in the entity classes?

These are my 2 classes

@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 Set candidateVideos = new HashSet();

    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=null;
    private String workStatus=null;

    private String desiredSalary=null;
    private String currentJobLevel=null;
    private String currentJobTitle=null;
    private String targetJobTitle=null;
    private String alternateTargetJobTitle1=null;
    private String alternateTargetJobTitle2=null;
    private String targetJobType=null;
    private String eventType=null;

    private String joinDate = null;
    private String lastLoginDate = null;

    //private SkillsBean skillsInfo;
    private Set skills = new HashSet();
    private Set candidateResumes = new HashSet();
    private Set targetJobCategoriesId = new HashSet();
    private Set targetJobLocationsId = new HashSet();


    public CandidateInfo() {
    }
    @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;
    }

    public void setAddress(String address) {
        this.address = 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;
    }

    @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;
    }
    @Column(name="skills")
    public String getSkills() {
        return skills;
    }

    public void setSkills(String skills) {
        this.skills = skills;
    }
    @Transient
    public int getRowCount() {
        return rowCount;
    }

    public void setRowCount(int count) {
        this.rowCount = count;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静若繁花 2024-11-17 08:53:01

你需要添加像这样的关系

@ManyToOne(cascade = CascadeType.ALL)
    public CandidateResumeInfo getCandidateResumeInfo () {
    return this.candidateResumeInfo ;
}

u need to add relation like

@ManyToOne(cascade = CascadeType.ALL)
    public CandidateResumeInfo getCandidateResumeInfo () {
    return this.candidateResumeInfo ;
}
挽手叙旧 2024-11-17 08:53:01

具有从 CandidateResumeInfoCandidateInfo 的多对一关联。

CandidateResumeInfo 类中添加新成员,

@ManyToOne()  
@JoinColumn(name = "candidate_userId")  
private CandidateInfo candidateInfo;  

// Also add getters and setters  

现在在查询中添加一个新别名,

crit.createAlias("candidateInfo", "candidateInfo");  
crit.add(Restrictions.in("candidateInfo.city", city));  

Have the many-to-one association from CandidateResumeInfo to CandidateInfo.

Add new member in CandidateResumeInfo class say,

@ManyToOne()  
@JoinColumn(name = "candidate_userId")  
private CandidateInfo candidateInfo;  

// Also add getters and setters  

Now in the query, add a new alias,

crit.createAlias("candidateInfo", "candidateInfo");  
crit.add(Restrictions.in("candidateInfo.city", city));  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文