0

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.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574

2 Answers2

0

You need to customize Your Informix typeHandeler:

assuming You are using myBatis add:

<typeHandlers>
    <typeHandler javaType="string" jdbcType="BLOB" handler="org.apache.ibatis.type.StringTypeHandler"/>
</typeHandlers>

at Your mybatis-config.xml file

hint: "javaType" should be Your desired type

JJB
  • 1
  • 1
0

Try using the @ElementCollection annotation as follows:

   @ElementCollection
   @CollectionTable(name="contact_ids", joinColumns=@JoinColumn(name="instance_id"))
   @Column(name="contact_id")
   public Set<Integer> contactIds;

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:

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "instance", cascade = {...})
    public Set<Contact> contacts;

and in your Contact class you also could have (to match the above):

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "instance_id", referencedColumnName = "instance_id", nullable = false)
public Instance instance;
Michael-7
  • 1,739
  • 14
  • 17
  • Thank you for the solution. I tried the first option but had an error as follows: – Godwin Anasigre Feb 09 '12 at 22:26
  • I tried the first option but had an error as follows:Caused by: java.sql.SQLException: The specified table (contact_ids) is not in the database. There is no direct relationship between instance and contact tables. The only relationship existing is that instance table has a collection of contact ids. Contact table has no instance id. I am working on an existing database and I dont want to change the table structure. I was thinking since the contact_ids field is a collection there is a way of retrieving the collection without creating any association just like retrieving a date or string. – Godwin Anasigre Feb 09 '12 at 22:37
  • Uhh, I didn't realize that the database structure was fixed and you didn't want to change it. In this case neither solution would immediately work. – Michael-7 Feb 09 '12 at 23:07