-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: how to create a two column left join in jpa/hibernate?
PostPosted: Thu Jan 26, 2012 5:38 am 
Newbie

Joined: Sun Sep 25, 2011 2:54 pm
Posts: 4
Is there a way to make a query in jpa/hibernate with a left join on two columns, like the following in plain sql?

Code:
select
    combinedin1_.SHIPMENTNUMBER ,
    shipmentin3_.INBOUNDDELIVERYITEM ,
    combinedin1_.PURCHASEORDERNUMBER,
    combinedin1_.PURCHASEORDERITEMNUMBER ,
    purchaseor2_.FACTORY
from
    REPORT.REPORTLINK this_
left outer join
    REPORT.COMBINEDINFO combinedin1_
        on this_.COMBINEDINFOID=combinedin1_.COMBINEDINFOID
left outer join
    REPORT.PURCHASEORDERINFO purchaseor2_
        on this_.PURCHASEORDERINFOID=purchaseor2_.PURCHASEORDERINFOID and purchaseor2_.DELETED='N'
left outer join
    REPORT.SHIPMENTINFO shipmentin3_
        on this_.SHIPMENTINFOID=shipmentin3_.SHIPMENTINFOID and shipmentin3_.DELETED='N'



More specific this is the left join written in plain sql:
Code:
left outer join
    REPORT.SHIPMENTINFO shipmentin3_
        on this_.SHIPMENTINFOID=shipmentin3_.SHIPMENTINFOID and shipmentin3_.DELETED='N'


This is my reportLink entity in JPA:

Code:
@Entity
@Table(name = "REPORTLINK") public class ReportLinkFull implements Serializable {
private static final long serialVersionUID = -2330676941570524461L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "REPORTLINKID")
private Integer id;

@ManyToOne
@JoinColumn(name = "SALESORDERINFOID")
private SalesOrderInfo salesOrderInfo;

@ManyToOne
@JoinColumn(name = "PURCHASEORDERINFOID")
private PurchaseOrderInfo purchaseOrderInfo;

@ManyToOne
@JoinColumn(name = "SHIPMENTINFOID")
private ShipmentInfo shipmentInfo;

@ManyToOne
@JoinColumn(name = "MATERIALINFOID")
private MaterialInfo materialInfo;

@ManyToOne
@JoinColumn(name = "CUSTOMERINFOID")
private CustomerInfo customerInfo;

@ManyToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(name = "COMBINEDINFOID")
private CombinedInfo combinedInfo;

@Version
private Integer version;

}



Thanks


Top
 Profile  
 
 Post subject: Re: how to create a two column left join in jpa/hibernate?
PostPosted: Thu Jan 26, 2012 6:34 am 
Newbie

Joined: Sun Sep 25, 2011 2:54 pm
Posts: 4
I found the answer:

Is is possible with the WITH operator:

Code:
em.createQuery("SELECT rl FROM ReportLinkFull rl "
            + "LEFT OUTER JOIN rl.shipmentInfo sh WITH sh.deleted = 'N' "
            + "LEFT OUTER JOIN rl.purchaseOrderInfo po WITH po.deleted = 'N'").getResultList();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.