【发布时间】:2011-10-16 02:04:04
【问题描述】:
我正在尝试使用 Hibernate 和 javax 持久性注释从数据库中填充此类中的数据。以下是相关的数据库结构。
table Poss_resp
ID qst_id resp_text
int int text
table Responses
ID qst_id usr_id resp_id
int int int int
我正在尝试使用 Responses.ID 和 Poss_resp.resp_text 填充下面显示的 Response 类。 Poss_resp 保存问题的可能答案。 Responses 包含给出的实际答案。 resp_id 是 Poss_resp 的外键。但是,我只想存储 resp_text 字符串,我不想要一个全新的对象。有没有办法做到这一点?我不知道如何告诉 Hibernate 如何使用除了 Response 的主键之外的东西,也没有确定正确的 JOIN 语法。
我的响应类:
@Entity
@Table(name="responses")
public class Response {
private long id;
private long qst_id;
private long resp_id;
private String resp_text;
/**
*
*/
public Response() {
// TODO Auto-generated constructor stub
}
/**
* @return the id
*/
@Id
@Generated(value="assigned")
@Column(name="ID")
public long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(long id) {
this.id = id;
}
/**
* @return the qst_id
*/
@Column(name="qst_id")
public long getQst_id() {
return qst_id;
}
/**
* @param qst_id the qst_id to set
*/
public void setQst_id(long qst_id) {
this.qst_id = qst_id;
}
/**
* @return the resp_id
*/
@Column(name="resp_id")
public long getResp_id() {
return resp_id;
}
/**
* @param resp_id the resp_id to set
*/
public void setResp_id(long resp_id) {
this.resp_id = resp_id;
}
/**
* @return the resp_text
*/
public String getResp_text() {
return resp_text;
}
/**
* @param resp_text the resp_text to set
*/
public void setResp_text(String resp_text) {
this.resp_text = resp_text;
}
如果可能的话,我更喜欢注释。
【问题讨论】:
-
那些JavaDoc cmets,怎么说呢,用处不大。
标签: java hibernate orm mapping