[英]Join columns of different types in Hibernate
I have 2 tables. 我有2张桌子。 Table1 has a column called 'id' which is a number. 表1有一个称为“ id”的列,它是一个数字。 Table2 has a column called entity_id
which is varchar
. Table2有一列称为entity_id
的列,该entity_id
varchar
。 Table1 has one to Many relation with Table2. 表1与表2具有一对多关系。
Here is my Hibernate mapping for Table1 这是我对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;
}
}
When I create a ctiteria with Table1 and try to list the data, I am getting Invalid number error because the type mismatch in the join column. 当我使用Table1创建一个标准条件并尝试列出数据时,由于连接列中的类型不匹配,我收到了无效数字错误。 can you please let me know how can I ast id to varchar? 能否请您告诉我如何将astchar分配给varchar?
为什么要在类型不匹配的地方选择那种设计?这是一种最佳实践,除非并且直到在这种例外情况下有确凿的用例之前,否则POJO和表中的数据类型必须一致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.