Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1022463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:28:12+00:00 2026-05-16T11:28:12+00:00

When using Blob -fields in n-to-m-relations Hibernate and MSSQL are failing for some reason.

  • 0

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?

[1] MSSQL error codes

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:28:12+00:00Added an answer on May 16, 2026 at 11:28 am

    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:

    DATASET       DATASET_DOCUMENT       DOCUMENT
    -------       ----------------       --------
    ID            DATASET_ID             ID
                  DOCUMENT_ID
    

    While a bidirectional will use the following representation:

    DATASET       DOCUMENT  
    -------       ----------
    ID            ID        
                  DATASET_ID
    

    In JPA 2.0, it is now possible to use a unidirectional association without a join table (in a standard way) by specifying a @JoinColumn on the @OneToMany side:

    @Entity
    class Dataset {
        @Id
        @Column(name="ID")
        public Long id;
        ...
        @OneToMany
        @JoinColumn(name="DATASET_ID", referencedColumnName="ID")
        public List<Document> documents = new ArrayList<Document>();
    }
    

    I would give the above a try.

    References

    • JPA 2.0 Specification
      • Section 11.1.21 “JoinColumn Annotation”
    • JPA Wikibook
      • Undirectional OneToMany, No Inverse ManyToOne, No Join Table (JPA 2.0)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to Azure and I'm using Blob storage to store some binary
I tried to uplad a pdf file using java.sql.PreparedStatement to mysql Blob field using
I am using Lightbox2 https://github.com/lokesh/lightbox2/blob/master/js/lightbox.js And I don't understand why all the inner members
I'm successfully using Node.js + Express + Everyauth ( https://github.com/abelmartin/Express-And-Everyauth/blob/master/app.js ) to login to
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
Using SQL Server 2008 R2 we are looking for a way to select the
I stored it images in the database using an BLOB field (I'm using SQLite).
I am struggling to decide if I should be using the MySQL blob field
I am storing a file in a MySQL BLOB field using PHP. Latter I
I want to save an image to the database using SQLite. I send the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.