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 9039329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:42:15+00:00 2026-06-16T09:42:15+00:00

Consider the following: @Entity public class Book { private List<String> authors; @ElementCollection public List<String>

  • 0

Consider the following:

@Entity
public class Book 
{ 
    private List<String> authors;
    @ElementCollection
    public List<String> getAuthors() {
        return authors;
    }

    public void setAuthors(List<String> authors) {
        this.authors = authors;
    }
}

How to type a JPA2 CriteriaQuery expression which, say, will let me find all the Books which have more than 2 authors?

  • 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-06-16T09:42:17+00:00Added an answer on June 16, 2026 at 9:42 am

    In JPQL:

    select b from Book where size(b.authors) >= 2
    

    Using the criteria API (but why would you replace such a simple static query with the following mess?):

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Book> criteriaQuery = cb.createQuery(Book.class);
    Root<Book> book = criteriaQuery.from(Book.class);
    Predicate predicate = cb.ge(cb.size(book.get(Book_.authors)), 2);
    criteriaQuery.where(predicate);
    criteriaQuery.select(book);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following Entity: @Entity public class Employee { @Id @GeneratedValue private Long id;
Please consider following sample @Entity public class Abc { @Id private Long id; @Unindexed
Consider the following code: @Entity @Table(name = a) public class A implements Serializable {
consider the following class and struct public class Entity { public IdType Id {get;set;}
To illustrate my question consider the following example: @Entity public class Box implements Serializable
Consider the following entity model: public class Agreement : Entity { public int AgreementId
Consider the following class hierarchy: public abstract class Entity { public virtual int Id
Consider following class public class AccountGroup : Entity<int> { public AccountGroup() { Accounts =
Consider the following simple example: [DataContract({0}Base)] public class Base<T> where T : Entity<T> {
Please consider the following two entities: @Entity @Table(name = PROFILE) public class Profile extends

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.