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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:45:41+00:00 2026-06-14T20:45:41+00:00

While retrieving a list of objects, I want to filter the results based on

  • 0

While retrieving a list of objects, I want to filter the results based on another table which I only have the ID of.The objects are NOT linked in the ORM-model, but instead just contain a UUID.

Ie:

@Entity
class A {
    @Id
    private UUID id;
    private UUID refB; // links to B
}

@Entity
class B {
    @Id
    private UUID id;
    private boolean visible;
}

I want to retrieve all A’s where B.hidden is false OR where B doesn’t exist.

In SQL I would do something like

SELECT t0.* FROM a_table t0 LEFT JOIN b_table t1 ON (t0.ref_b = t1.id)
    WHERE t1.hidden IS NULL OR t1.hidden = 0;

The reason I’m not just using RawSql is that I cannot find any way to use wildcards in the select, so all the attributes would have to be both maintained and manually added in the select.

I have also tried

List<A> listA = Ebean.find(A.class).where()
     .join("LEFT JOIN b_table t1 ON (t0.ref_b = t1.id)")
     .where().in("t1.hidden", "0", "NULL");

But then I get an error because WHERE is put before “LEFT JOIN”.

I assume that the “right” way would be to replace “private UUID refB” with “private B refB”. But doing that would make it easier to circumvent certain security measures.

Is this possible or will I have to add all attributes in a RawSql?

  • 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-14T20:45:43+00:00Added an answer on June 14, 2026 at 8:45 pm

    Filtering in Ebean is for other purposes than just manipulating the WHERE clause, look at the comparison in other question.

    Here you have a proper way (I changed models to show complete, working sample)

    Models

    @Entity
    public class A extends Model {
    
        @Id
        public Integer id;
    
        @ManyToOne
        public B b;
    
        public static Finder<Integer, A> find
                    = new Finder<Integer, A>(Integer.class, A.class);
    
    }
    
    @Entity
    public class B extends Model {
    
        @Id
        public Integer id;
        public Boolean hidden;
    
        public static Finder<Integer, B> find
                = new Finder<Integer, B>(Integer.class, B.class);
    
    }
    

    Controller

    public static Result index() {
    
        // Insert some data one every request
        B bFalse = new B();
        bFalse.hidden = false;
        bFalse.save();
    
        B bTrue = new B();
        bTrue.hidden = true;
        bTrue.save();
    
        A a1 = new A();
        a1.b = bFalse;
        a1.save();
    
        A a2 = new A();
        a2.b = bTrue;
        a2.save();
    
        A a3 = new A();
        a3.b = bTrue;
        a3.save();
    
        // Let's search...
        List<A> aListOfNotHidden = A.find.where().and(Expr.eq("b.hidden", false), Expr.isNotNull("b.hidden")).findList();
        for (A a : aListOfNotHidden) {
            Logger.info("NOT hidden " + a.id);
        }
    
        List<A> aListOfHidden = A.find.where().eq("b.hidden", true).findList();
        for (A a : aListOfHidden) {
            Logger.warn("HIDDEN " + a.id);
        }
    
        return ok("check logs in your console");
    }
    

    Result SQLs of H2

    -- all NOT hidden
    select t0.id c0, t0.b_id c1
    from a t0
    left outer join b t1 on t1.id = t0.b_id
    where (t1.hidden = false  and t1.hidden is not null ) 
    
    -- all hiden
    select t0.id c0, t0.b_id c1 
    from a t0
    left outer join b t1 on t1.id = t0.b_id  
    where t1.hidden = true 
    

    Alternatively you can also use SqlQuery to fetch just a SqlRows (not objects) check linked APIs for samples of usage, setting named parameters etc.:

    List<SqlRow> rows = Ebean.createSqlQuery("select t0.*  " +
            "from a t0 left outer join b t1 on t1.id = t0.b_id " +
            "where (t1.hidden = false  and t1.hidden is not null ) ").findList();
    
    
    for (SqlRow row : rows) {
        // do something with each row here, use methods such 
        // as getString("fieldname") for retrieving data  
        // (from SqlRow API)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem while retrieving the records which are not older than 30 days.
I have a question about retrieving data values which are sent from a web
I have a table with a list of businesses. Each row has details such
I am retrieving 4 Fields from my database table. Now i want to add
I have draggable list of < li > elements which I'm able to drag
I am trying simple linked list Collection program, but it is not giving me
I have a table like this list | id | -----------+-------- {930,23} | 1
i posted some data using tinymce (in a symfony project).while retrieving back how can
I am using durpal 6. while retrieving data i got the following output: |
While debugging and keep pressing F5, if the source code does not exist, eclipse

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.