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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:43:04+00:00 2026-05-27T15:43:04+00:00

Here is the deal I have a one to many relationship between User and

  • 0

Here is the deal I have a one to many relationship between User and Post

@Entity
public class User extends Model {
...
  @OneToMany(cascade = CascadeType.ALL, targetEntity = Post.class, mappedBy = "author")
  @OrderBy("createdAt DESC")
  public List<Post> posts;
...
}

@Entity
public class Post extends Model {
...
  public int privacy; // 0=public, 1=private
  @ManyToOne
  public User author;
...
}

Works beautifully… Now I want to retrieve the public posts from the users? Of course iterating over the result and deleting the private posts is not an option, I ultimately need to do some pagination, and that would become a headache. Is there some annotation that could help me out with that?

  • 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-27T15:43:04+00:00Added an answer on May 27, 2026 at 3:43 pm

    Something like this ?

    User author = User.findById(1);  
    int pageNumber = 1;
    int pageSize = 10;
    Post.find("FROM Post WHERE author = ? AND privacy = 0", author).fetch(pageNumber, pageSize);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the deal. I have a big class hierarchy and I have this one
I have two entities with a Unidirectional Many-to-One mapping. Here's Product : use Doctrine\Common\Collections\ArrayCollection;
In my database, Concessions have a many-to-one relationship with Firms (each Concession has a
Here's the deal : I have Publication objets in my application. I also have
Here is the deal, in my Java project I have to make a composite
I have been struggling with this for months in my project. Here's the deal:
OK, here's the deal. I have Git installed on my Debian (lenny) remote server.
I have a class called Deal. Deal has vote_scores. I would like to see
Here is the deal: I have 2 computers connected via switch. Both computers can
Ok, this is a biggie. Here's the deal: I have upwards of 50 installs

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.