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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:31:14+00:00 2026-05-12T13:31:14+00:00

I need to make an outer join query that retrieves all of the definitions

  • 0

I need to make an outer join query that retrieves all of the definitions and any properties they have associated with them that are associated with a certain company.

I have two Hibernate models objects:

class PropertyDefinition {
    @Id
    private Long id;

    @Column
    private String name;

    @OneToMany(mappedBy = "propertyDefinition")
    private Set<Property> properties = new HashSet<Property>();
}

class Property {
   @Id
   private Long id;

   @ManyToOne
   private Integer companyId;

   @ManyToOne
   private PropertyDefinition propertyDefinition;
}

So the query ends up looking like:

from PropertyDefinition as pd left join pd.properties as props with props.companyId = :companyId

So all is peachy so far. The problem I’m having is what sort of structure do I store the returned data in? Hibernate returns a List where [0] is the PropertyDefinition (should never be null) and [1] is the possibly null Property.

My issues:

  • Its obnoxious and not very OO friendly to pass around the List of Object[]s.
  • I can’t just hold onto the PropertyDefinition because the list of properties it holds isn’t limited to the company.
  • I could create a simple object that holds a reference to the PropertyDefinition and a possibly null Property but its inefficient to have to iterate through the entire List and put each into this new object.

Anyone have a suggestion for a better query or a better mapping structure? I’d really appreciate any assistance.

  • 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-12T13:31:14+00:00Added an answer on May 12, 2026 at 1:31 pm

    Well, normally left join on collection is best handled via fetch which returns a list of container objects with populated collections. However, since you’re using with condition, that won’t work for you.

    If you were to create a simple holder for PropertyDefinition and Property with appropriate public constructor, you could tell Hibernate to return that:

    select new Holder(pd, props)
      from PropertyDefinition as pd
      left join pd.properties as props
      with props.companyId = :companyId
    

    It should take care of the issues you’ve listed; it’s not ideal but probably is the best solution available under the circumstances.

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

Sidebar

Related Questions

I have a need for a run once query (so performance isn't that critical)
I have a query that I don't think should be that hard to make,
I have written a Linq query to do an outer join on multiple columns.
I have a reasonably long SQL query that I need to run in a
I need make all of my posts update. I use bulk upload for store,
I need to make a series (1-20) ajax calls and I need to have
I need to make the top header of a report disappear. The part that
I need some help with a MySQL query I'm working on. I have data
I have a design that uses two outer columns, and within one of the
I need to access an alias from the outer query in the subquery, like

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.