Note that there are some explanatory texts on larger screens.

plurals
  1. POGood object structure for results of my Hibernate left outer join
    primarykey
    data
    text
    <p>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. </p> <p>I have two Hibernate models objects: </p> <pre><code>class PropertyDefinition { @Id private Long id; @Column private String name; @OneToMany(mappedBy = "propertyDefinition") private Set&lt;Property&gt; properties = new HashSet&lt;Property&gt;(); } class Property { @Id private Long id; @ManyToOne private Integer companyId; @ManyToOne private PropertyDefinition propertyDefinition; } </code></pre> <p>So the query ends up looking like: </p> <pre><code>from PropertyDefinition as pd left join pd.properties as props with props.companyId = :companyId </code></pre> <p>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.</p> <p>My issues:</p> <ul> <li>Its obnoxious and not very OO friendly to pass around the List of Object[]s.</li> <li>I can't just hold onto the PropertyDefinition because the list of properties it holds isn't limited to the company.</li> <li>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.</li> </ul> <p>Anyone have a suggestion for a better query or a better mapping structure? I'd really appreciate any assistance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload