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

want to add two different tables(classes) in one hibernate criteria

我有这个密码

1
2
3
4
ArrayList<String> city = 'Anniston';

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

现在我想添加以下条件

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

但问题是,cities列不在CandidateResumeInfo.classITS的candidateinfo类中。

任何关于如何在上面的标准中添加这个标准,以及如何在上面的标准中添加CandidateInfo类的想法。

我想我需要连接或链接这两个表,但是如何,实体类中会有什么变化吗?

这是我的两个班

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
@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;
    }


有从CandidateResumeInfoCandidateInfo的多对一关联。

CandidateResumeInfo类中添加新成员,比如,

1
2
3
4
5
@ManyToOne()  
@JoinColumn(name ="candidate_userId")  
private CandidateInfo candidateInfo;  

// Also add getters and setters

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

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

你需要像这样添加关系

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