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

  • Home
  • SEARCH
  • 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 7585041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:04:36+00:00 2026-05-30T19:04:36+00:00

I have a book entity which has a OneToMany relationship set up to Document

  • 0

I have a book entity which has a OneToMany relationship set up to Document entity. In other words, in Hibernate, my book entity returns a list of Documents as the property docs.

I want to return a list of documents for a user which have not been assigned to a book, yet. Here is my jpql query, and I’ve finagled it every way I can, and I can’t get it to work:

select d from Document d WHERE d.user = :user
AND NOT EXISTS( SELECT b.docs from Book b WHERE b.docs = d )

Where Book is an entity, User is an entity passed in, b.docs is a list of Documents, and Document(d) is an entity.

What am I doing wrong? With this particular version of the query, I’m receiving the error:

org.hibernate.TypeMismatchException: left and right hand sides of a binary logic
operator were incompatibile
[java.util.Collection(com.fallenjusticestudios.bardwalk.model.Book.docs) : com.fallenjusticestudios.bardwalk.model.Document]

Book:

@Entity
@Table(name="book")
public class Book {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;

    @Column
    @NotEmpty
    @NotNull
    private String title;

    @Column
    @NotEmpty
    @NotNull
    private String description;

    @ManyToOne(cascade=CascadeType.MERGE, targetEntity=User.class)
    @JoinColumn(name="user")
    private User user;

    @OneToMany(cascade=CascadeType.MERGE, fetch=FetchType.LAZY, targetEntity=Document.class)
    @JoinColumn(name="document_id",referencedColumnName="id")
    private List<Document> docs;


    // Will need to add Contest to the fields later on.
    //
    //


    public Long getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public String getDescription() {
        return description;
    }

    public User getUser() {
        return user;
    }

    public List<Document> getDocs() {
        return docs;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setDocs(List<Document> docs) {
        this.docs = docs;
    }





}

UPDATE:

Another try:

Query:

select d from Document d WHERE d.user = :user
AND NOT EXISTS( SELECT Document from Book.docs b WHERE b.id = dn.id )

org.hibernate.hql.ast.QuerySyntaxException: Book.docs is not mapped [select d from com.fallenjusticestudios.bardwalk.model.Document d WHERE d.user = :user AND NOT EXISTS( SELECT Document from Book.docs b WHERE b.id = dn.id)]

UPDATE2:

I figured this out. I was going about the query all wrong. Solution query was:

select d from Document d WHERE d.user = :user
AND NOT d IN( SELECT d from Book b, IN(b.docs) bd WHERE bd.id = d.id )
  • 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-30T19:04:37+00:00Added an answer on May 30, 2026 at 7:04 pm

    I figured this out. I was going about the query all wrong. Solution query was:

    select d from Document d WHERE d.user = :user
    AND NOT d IN( SELECT d from Book b, IN(b.docs) bd WHERE bd.id = d.id )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I have a CoreData entity named, say, 'Book', which has a one-to-one relationship
I have an entity Book which holds a many-to-one relation with a Publisher. Here
If I have Book object which has a child collection of Comments, Can I
Let's say I have an entity Author which has a name can write 0
If I have an entity that has an association (e.g. Book.Publisher), how do I
context: I have an entity Book. A book can have one or more Descriptions.
I have a large list of entities which the user needs to be able
I build an application which use Hibernate JPA2 + Spring. I have problem with
I have created a Entity Framework mapping based on the book Microsoft Entity Framework
I have two objects with a many to many relationship, let's call them Book

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.