こんにちは、User
とCandidate
テーブルに参加しようとしています。私は列firstname
、lastname
、email
、phone
からCandidate
からテーブルと参加するpassword
の列User
のテーブルをしたい。私はこれをやってみましたが、何らかのエラーが発生しました。私のコードは以下のとおりである:休止状態でテーブルを結合するエラー
CREATE TABLE `candidate` (`candidate_id` bigint(12) NOT NULL,`user_id` int(11) DEFAULT NULL,`firstname` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,`lastname` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,`dob` date DEFAULT NULL,`gender` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,`email` varchar(100) COLLATE utf8_unicode_ci NOT NULL,`phone` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,`address_id` int(11) DEFAULT NULL,`profile_title` varchar(120) COLLATE utf8_unicode_ci DEFAULT NULL,`profile_summary` varchar(10000) COLLATE utf8_unicode_ci DEFAULT NULL,`total_experience` int(11) DEFAULT NULL COMMENT 'year,month',`current_location` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,`current_salary` double DEFAULT NULL,`expected_salary` double DEFAULT NULL,`status` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,`percentage` int(45) DEFAULT NULL,`updated_on` timestamp NULL DEFAULT CURRENT_TIMESTAMP,`noticeperiod` int(11) DEFAULT NULL,`martialstatus` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,`currentoffer` double DEFAULT NULL,`idproof` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,`industry` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,`functionalarea` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,`functionalrole` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,`resign` bit(1) DEFAULT NULL,`preferlocation` varchar(1000) COLLATE utf8_unicode_ci DEFAULT NULL,`type` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,`notice_period_update` timestamp NULL DEFAULT NULL,`passport` bit(1) DEFAULT NULL,`gross_salary` double DEFAULT NULL,`profile_type` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL,`rrm_user_id` int(11) DEFAULT NULL, PRIMARY KEY (`candidate_id`), KEY `Candidate_Address_idx` (`address_id`),KEY `Can_user` (`user_id`),KEY `CandidateStatus_idx` (`status`),KEY `CandidatePercent_idx` (`percentage`), KEY `user_id_idx` (`rrm_user_id`),CONSTRAINT `Can_user` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT `Candidate_Address` FOREIGN KEY (`address_id`) REFERENCES `address`(`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `user_id` FOREIGN KEY (`rrm_user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
私のユーザーテーブル:
CREATE TABLE `user` (`id` int(11) NOT NULL AUTO_INCREMENT,`username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,`password` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,`first_name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,`last_name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,`type` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,`active` bit(1) DEFAULT NULL,`deleted` bit(1) DEFAULT NULL,`timezone` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,`created_on` timestamp NULL DEFAULT NULL,`updated_on` timestamp NULL DEFAULT CURRENT_TIMESTAMP,`activationcode` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,`secure_key` varchar(16) COLLATE utf8_unicode_ci DEFAULT NULL,PRIMARY KEY (`id`),UNIQUE KEY `username_UNIQUE` (`username`)) ENGINE=InnoDB AUTO_INCREMENT=1505 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
私のエンティティクラス:ユーザー表の
@Table(name = "CANDIDATE")public class SignUp {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String candidate_id;
@Column
private String firstname;
@Column
private String lastname;
@Column
private String email;
@Column
private String phone;
public String getCandidate_id() {
return candidate_id;
}
public void setCandidate_id(String candidate_id) {
this.candidate_id = candidate_id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "candidate_id")
private Password password;
public Password getPassword() {
return password;
}
public void setPassword(Password password) {
this.password = password;
}
:
@Table(name = "USER")public class Password { @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;
@Column
private String password;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id")
private SignUp signUp;
public SignUp getSignUp() {
return signUp;
}
public void setSignUp(SignUp signUp) {
this.signUp = signUp;
}
エラーメートルになっているが:
Hibernate:
select
password0_.id as id1_1_0_,
password0_.password as password2_1_0_,
password0_.user_id as user_id4_1_0_,
signup1_.candidate_id as candidat1_0_1_,
signup1_.email as email2_0_1_,
signup1_.firstname as firstnam3_0_1_,
signup1_.lastname as lastname4_0_1_,
signup1_.phone as phone5_0_1_
from
User password0_
left outer join
CANDIDATE signup1_
on password0_.user_id=signup1_.candidate_id
where
password0_.id=?
Jun 01, 2017 4:48:45 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 1054, SQLState: 42S22 Jun 01, 2017 4:48:45 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: Unknown column 'password0_.user_id' in 'field list'
私たちはどのように組み立てる/ Javaコードからクエリを呼び出す –
申し訳ありませんが、私はあなたを取得しませんでしたか? – mehul
なので、.. getCurrentSession()。createQuery(QUERY).uniqueResult();のようなものを呼び出すとき。その質問に興味があるのは –