title: Hibernate Left Outer Join
body: <p>I have a Hibernate service method as such: <code>"SELECT sc FROM SecurityContact sc WHERE sc.securityId=:securityId2"</code>. securityId2 is passed in by the user. Each SecurityContact has a many to one relationship with a Contact, so Hibernate automatically calls a join when this query runs. However, the join that Hibernate always runs is an inner join, which will not work properly for my purposes. Is there any way to force Hibernate to internally generate a left outer join instead? Here is the code for the SecurityContact class:</p>
  
  <pre><code>/**
   * The persistent class for the SecurityContact database table.
   * 
   */
  @Entity
  @FXClass(kind=FXClassKind.REMOTE)
  public class SecurityContact implements Serializable {
      private static final long serialVersionUID = 1L;
      @Transient private String uid;
      @FXIgnore
      public String getUid() {
          if (uid == null) {
              uid = "" + securityContactId;
          }
          return uid;
      }
  
      public void setUid(String uid) {
          this.uid = uid;
      }
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name="securityContact_id")
      private Long securityContactId;
  
      @Column(name="security_id")
      private String securityId;
  
      @Column(name="create_date")
      private String createDate;
  
      @Column(name="create_user")
      private String createUser;
  
      @Column(name="modify_date")
      private String modifyDate;
  
      @Column(name="modify_user")
      private String modifyUser;
  
      //bi-directional many-to-one association to AgentContact
  
      @ManyToOne
      @JoinColumn(name="agent_id", referencedColumnName="contact_id")
      private AgentContact agentContact;
  
      //bi-directional many-to-one association to AuditContact
      @ManyToOne
      @JoinColumn(name="audit_id", referencedColumnName="contact_id")
      private AgentContact auditContact;
  
      public SecurityContact() {
      }
      @FXKeyColumn
      public Long getSecurityContactId() {
          return this.securityContactId;
      }
  
      public void setSecurityContactId(Long securityContactId) {
          this.securityContactId = securityContactId;
      }
  
      public String getSecurityId() {
          return this.securityId;
      }
  
      public void setSecurityId(String securityId) {
          this.securityId = securityId;
      }
  
      public String getCreateDate() {
          return this.createDate;
      }
  
      public void setCreateDate(String createDate) {
          this.createDate = createDate;
      }
  
      public String getCreateUser() {
          return this.createUser;
      }
  
      public void setCreateUser(String createUser) {
          this.createUser = createUser;
      }
  
      public String getModifyDate() {
          return this.modifyDate;
      }
  
      public void setModifyDate(String modifyDate) {
          this.modifyDate = modifyDate;
      }
  
      public String getModifyUser() {
          return this.modifyUser;
      }
  
      public void setModifyUser(String modifyUser) {
          this.modifyUser = modifyUser;
      }
      @FXManyToOne(parent="parent", property="contactId")
      public AgentContact getAgentContact() {
          return this.agentContact;
      }
  
      public void setAgentContact(AgentContact agentContact) {
          this.agentContact = agentContact;
      }
      @FXManyToOne(parent="parent", property="contactId")
      public AgentContact getAuditContact() {
          return this.auditContact;
      }
  
      public void setAuditContact(AgentContact auditContact) {
          this.auditContact = auditContact;
      }
  
  } 
  </code></pre>