【发布时间】:2014-12-31 04:52:40
【问题描述】:
我有 2 张桌子。 Table1 有一个名为“id”的列,它是一个数字。 Table2 有一个名为entity_id 的列,即varchar。 Table1 与 Table2 是一对多的关系。
这是我对 Table1 的 Hibernate 映射
@Entity
@Table(name="Table1")
public class Table1 implements Serializable {
private long id;
private List<Table2> notes;
@Id
@Column(name="ID")
public long getId() {
return id;
}
public void setId(long id) {
this.id= id;
}
@OneToMany(fetch=FetchType.EAGER,targetEntity=Table2.class)
@Fetch(FetchMode.JOIN)
@JoinColumn(name="ENTITY_ID",referencedColumnName="ID")
public List<Table2> getNotes() {
return storeNotes;
}
public void setNotes(List<Table2> notes) {
this.notes = notes;
}
}
当我使用 Table1 创建一个 ctiteria 并尝试列出数据时,我收到 Invalid number 错误,因为连接列中的类型不匹配。你能告诉我如何将 id 转换为 varchar 吗?
【问题讨论】:
-
类型是为了帮助我们编写正确的代码而不是乱码。您可能需要考虑重新设计数据结构。
-
显示您尝试过的程序并显示异常的完整堆栈跟踪。