使用 hibernate 从数据库中检索一组原始类型
我使用的是 informix 数据库,并且有两个表;实例及联系方式。联系人表有以下字段; contact_id、fname 和 lname。实例表具有以下字段,instance_id、name 和 contact_ids(contact_ids 是 contact ids 的 informix set 集合,com.informix.jdbc.IfxCollection@429681e8)。 我使用hibernate进行数据持久化。我的实例类的代码如下所示:
@Entity
public class Instance{
@Id
private int instance_id;
private String name;
@Lob
private Set<Integer> contact_ids
....
setters and getters
}
联系人类:
@Entity
public class Contact{
@Id
private int contact_id;
private String fname;
private String lname;
....
setters and getters
}
当我加载实例实体时,出现以下错误:
20:32:18,527 ERROR [jsp:154] java.sql.SQLException: **Can't convert to: binary stream**
at com.informix.util.IfxErrMsg.getSQLMinorException(IfxErrMsg.java:575)
at com.informix.jdbc.IfxObject.toBlob(IfxObject.java:647)
at com.informix.jdbc.IfxResultSet.getBlob(IfxResultSet.java:3338)
at com.informix.jdbc.IfxResultSet.getBlob(IfxResultSet.java:3437)
我只想检索该集合。
I am using an informix database and I have two tables; instance and contact. Contact table has the following fields; contact_id, fname and lname. Instance table has the following fields, instance_id, name and contact_ids(contact_ids is an informix set collection of contact ids, com.informix.jdbc.IfxCollection@429681e8).
I use hibernate for data persistence. The code for my Instance Class looks like this:
@Entity
public class Instance{
@Id
private int instance_id;
private String name;
@Lob
private Set<Integer> contact_ids
....
setters and getters
}
Contact Class:
@Entity
public class Contact{
@Id
private int contact_id;
private String fname;
private String lname;
....
setters and getters
}
When I load an Instance Entity I get the following error:
20:32:18,527 ERROR [jsp:154] java.sql.SQLException: **Can't convert to: binary stream**
at com.informix.util.IfxErrMsg.getSQLMinorException(IfxErrMsg.java:575)
at com.informix.jdbc.IfxObject.toBlob(IfxObject.java:647)
at com.informix.jdbc.IfxResultSet.getBlob(IfxResultSet.java:3338)
at com.informix.jdbc.IfxResultSet.getBlob(IfxResultSet.java:3437)
I simply want to retrieve the set.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 @ElementCollection 注释,如下所示:
但是,对于您的场景,我建议实际实体本身之间存在 OneToMany 关系,因此在您的实例类中,您将拥有:而不是 contactIds 字段:
并且在您的 Contact 类中,您还可以有(与上面匹配):
Try using the @ElementCollection annotation as follows:
However, for your scenario, I would recommend a OneToMany relationship between the actual entities themselves, so in your instance class, instead of the contactIds field, you'd have:
and in your Contact class you also could have (to match the above):
您需要自定义您的 Informix typeHandeler:
假设您正在使用 myBatis 添加:
在您的 mybatis-config.xml 文件
提示:“javaType”应该是您想要的类型
You need to customize Your Informix typeHandeler:
assuming You are using myBatis add:
at Your mybatis-config.xml file
hint: "javaType" should be Your desired type