Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate 4.3.6 QuerySyntaxException: Path expected for join

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.

like image 889
RanPaul Avatar asked Feb 12 '23 01:02

RanPaul


1 Answers

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.

like image 108
Radim Köhler Avatar answered Mar 18 '23 05:03

Radim Köhler