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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:19:17+00:00 2026-05-23T01:19:17+00:00

I have entities: Tweet and User . Tweet has an author , which is

  • 0

I have entities: Tweet and User.

Tweet has an author, which is an instance of User class. User is following others users and also keeps track of users following him:

@ManyToMany
public List<User> following;

@ManyToMany(mappedBy = "following", fetch = FetchType.LAZY)
public List<User> followedBy;

Now I’d like to load tweets of users that I’m currently following. I tried this:

"FROM Tweet AS tweet " +
                "JOIN tweet.author as author " +
                "JOIN author.followedBy as followedBy " +
                "WHERE tweet.author = followedBy AND ? in followedBy ORDER BY dateCreated DESC"

But it doesn’t work. I suck in sophisticated queries.

EDIT

Generated query, which I copied from the exception which was thrown:

SELECT TWEET0_.ID AS ID10_, TWEET0_.AUTHOR_ID AS AUTHOR4_10_, TWEET0_.CONTENT AS CONTENT10_, TWEET0_.DATECREATED AS DATECREA3_10_ 
  FROM TWEET TWEET0_ 
  INNER JOIN USER USER1_ ON TWEET0_.AUTHOR_ID=USER1_.ID 
    WHERE USER1_.ID IN 
      (SELECT .[*] FROM USER USER2_, USER_USER FOLLOWING3_, USER USER4_ WHERE USER2_.ID=FOLLOWING3_.FOLLOWEDBY_ID AND FOLLOWING3_.FOLLOWING_ID=USER4_.ID AND USER2_.ID=?) 
ORDER BY TWEET0_.DATECREATED DESC LIMIT ?

Edit 2

Unfortunately, now I’m getting IllegalArgumentException:

    IllegalArgumentException occured : 
org.hibernate.QueryException: illegal attempt to dereference collection [user2_.id.following] with element property reference [id] [select tweet from models.Tweet tweet join tweet.author author where author in (select user.following.id from models.User user where user.id = :id) order by tweet.dateCreated desc] 
  • 1 1 Answer
  • 2 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-23T01:19:17+00:00Added an answer on May 23, 2026 at 1:19 am

    I’d use a subquery here:

    select tweet from Tweet tweet
    join tweet.author author
    where author in 
    (select following.id from User user join user.following following where user.id = :id) 
    order by tweet.dateCreated desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have entities Group and User . the Group entity has Users property which
I have two entities: Recipe and Ingredient. Entites: public class Ingredient { public int
I have two entities A and B. public class A{ @Id @GeneratedValue private Integer
I have 2 entities in CoreData (which are relevant to this). Let's call them
I have three entities: Country, State and City with the following relationships: When creating
I have 3 entities like this: sorry that this image has a problem that
Let's say I have entities A, B, C and each A has many B
If I have entities like: @Entity public class Person { public String name; @OneToMany
hey guys, say I have Entities and mappings like this: public class Episode {
I have two entities, Parent and Child, in Entity Framework. The parent has a

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.