Am having problem with HQL join query. Can anyone tell me whats wrong with my below join HQL query? Am using Hibernate 4.3.6, JDK 7 and Groovy 2.2
def query = 'select lip.referenceId from Parcel as lip left join TransportFile tf where lip.statusDisplayName != tf.statusDisplayName'
def hqlQuery = session.createQuery(query)
def hqlcount = hqlQuery.list().size
Am getting the below error when i run above code
com.dc.core.common.exception.BaseApplicationException: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [select lip.referenceId from com.dc.apps.cp.ebilling.model.impl.Parcel as lip left join TransportFile tf where lip.statusDisplayName != tf.statusDisplayName]
Below is my Parcel entity
package com.dc.apps.cp.ebilling.model.impl
@Entity
@Audited
public class Parcel implements IPersistentEntityInstance {
private static final long serialVersionUID = 1L;
private Long id;
@AttributeReadPermission(name = "SUBMITTEDFILE.READ")
@AttributeWritePermission(name = "SUBMITTEDFILE.UPDATE")
private File submittedFile;
private ParcelType type;
private boolean isBeingSubmitted;
private TransportFile transportFile;
}
Below is my TransportFile entity
package com.dc.apps.cp.legacy.model.impl;
@Entity
@EntityMetadataDefaults(editable = false)
public class TransportFile implements ITransportObject {
private static final long serialVersionUID = 1L;
private Long id;
private String statusDisplayName;
// [ReferenceID] [varchar](30) NOT NULL
private String referenceId;
// [sent] [datetime] NULL,
private Timestamp sentDate;
// [received] [datetime] NULL,
private Timestamp receivedDate;
// [Status] [varchar](4) NULL,
private String statusCode;
private List<TransportLog> TransportLogs;
private String rejectionReason;
}
I refered to this post HQL left join: Path expected for join but I dont see any anything worng my HQL join query.
This exception "Path expected for join" is saying:
Provide a path from one entity, to the other. The join is defined by the mapping
So we would need:
select lip.referenceId
from Parcel as lip
// instead of this
// left join TransportFile tf
// we need a path from Parcel to TransportFile
left join lip.transportFile tf
where lip.statusDisplayName != tf.statusDisplayName'
...
The statement left join TransportFile tf
is more like a SQL... which is not the case for HQL.
Our statement must be expressing navigation: left join lip.transportFile tf
- i.e. join the transportFile
which is related to lip
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With