When using Blob-fields in n-to-m-relations Hibernate and MSSQL are failing for some reason.
SQL Error: 421, SQLState: S0001
The image data type cannot be selected as DISTINCT because it is not comparable.
...
could not initialize a collection: [Dataset.documents#someID]
My classes look as follows:
@Entity
class Dataset {
@OneToMany(fetch = FetchType.LAZY)
public List<Document> documents = new ArrayList<Document>();
}
@Entity
class Document {
@Id
public long id;
@Lob
public byte[] data;
}
Any ideas on this? I already tried using a Set or Document[] to avoid the errors. It seems that Hibernate always tries a distinct SELECT on my tables. How can I workaround this?
It would have been interesting to post the executed queries and the tables. But one difference I can think of between the two mappings (unidirectional one-to-many vs a bidirectional) is the way they’re represented at the database level.
By default, a unidirectional one-to-many will use a join table:
While a bidirectional will use the following representation:
In JPA 2.0, it is now possible to use a unidirectional association without a join table (in a standard way) by specifying a
@JoinColumnon the@OneToManyside:I would give the above a try.
References