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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:46:55+00:00 2026-06-11T17:46:55+00:00

I have an Entity BlogPosts with yml mapping: type: entity table: blog_posts id: id:

  • 0

I have an Entity “BlogPosts” with yml mapping:

type: entity
table: blog_posts
id:
  id:
    type: integer
    generator: { strategy: AUTO }
fields:
  body:
    type: text
  created_at:
    type: datetime
manyToMany:
  replies:
    targetEntity: BlogPosts
    inversedBy: replyTo
    orderBy: {"id": "DESC"}
    orphanRemoval: true
    joinTable:
      name: blog_post_replies
      joinColumns:
        reply_to_id:
          referencedColumnName: id
      inverseJoinColumns:
        reply_id:
          referencedColumnName: id
  replyTo:
    targetEntity: BlogPosts
    mappedBy: replies
manyToOne:
  user:
    targetEntity: User
    inversedBy: posts
    joinColumns:
      user_id:
        referencedColumnName: id
        nullable: false

The problem is, when i try to fetch the data using a JOIN, the result is empty.

    $query = $em->createQuery("SELECT p, rl FROM <Bundle>:BlogPosts p JOIN p.replies rl WHERE p.user = 1");
    $posts = $query->getResult(); // Returns empty array

But it works perfectly without a join:

    $query = $em->createQuery("SELECT p FROM <Bundle>:BlogPosts p WHERE p.user = 1");
    $posts = $query->getResult(); // Works as intended

What am i missing? I am really desperate 🙁

EDIT:
Just found out, that it returns only posts, that have replies. How can i select all posts and if it has replies, replies too?

  • 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-11T17:46:56+00:00Added an answer on June 11, 2026 at 5:46 pm

    So i found the problem! Instead of JOIN i used LEFT JOIN:

    $query = $em->createQuery("SELECT p, rl FROM <Bundle>:BlogPosts p LEFT JOIN p.replies rl WHERE p.user = 1");
    $posts = $query->getResult(); // Now it works like a charm!
    

    So now MySQL joins the result to the blog posts! When using a simple JOIN, it tries to join the posts to the replies, in witch case the result will be empty if the post doesn’t have any!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I have entity B inherit from entity A using table-per-type for storage and
I used JPA and mysql. Each table have entity class.I have four tables. Table1
I have an entity defined as follows @Entity(name = Report) @Table(name = REPORTS) @org.hibernate.annotations.Entity(dynamicInsert
i have Entity mapped to table TABLE1 with columns COLUMN1 and COLUMN2 i have
I have Entity A with ID APK having two long fields, that is ids
I have Entity Data Model using ADO.NET Entity Data Model (using auto generate from
Technology: Hibernate 3.0 Suppose i have Entity class Company @Entity @Table(name=tbl_companies) public class Company
I'm trying to use composition in hibernate with annotations. I have: @Entity @Table(name =
I have Entity type class(Serializable, loaded and saved data at runtime) where user specified
I have entity for Doctrine: <?php /** * @Entity * @Table(name=orders) */ class Orders

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.