64052

hql inner join Path expected for join! error

Question:

hi have following entities;

@Entity public class FilesInfo { @Id @GeneratedValue private Integer id; private String name; private String url; @OneToMany(cascade= CascadeType.ALL) @JoinColumn(name="fileId") private Collection<FilesShare> filesShared = new ArrayList<FilesShare>(); public Collection<FilesShare> getFilesShared() { return filesShared; } public void setFilesShared(Collection<FilesShare> filesShared) { this.filesShared = filesShared; } //getters & setters }

the other one

@Entity public class FilesShare { private Integer id; private int userId; private int owner; }

the resultand tables are:

mysql> desc filesshare; +--------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+---------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | userId | int(11) | NO | | NULL | | | owner | int(11) | NO | | NULL | | | fileId | int(11) | YES | MUL | NULL | | +--------+---------+------+-----+---------+----------------+ 4 rows in set (0.01 sec) mysql> desc filesinfo; +-------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(255) | YES | | NULL | | | url | varchar(255) | YES | | NULL | | +-------+--------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)

i want to make the hql as i made the sql below:

select a.id, a.name, a.url from FilesInfo a inner join FilesShare b on a.id=b.fileid where b.userid=5 and b.owner=1;

that gives the following output:

mysql> select a.id, a.name, a.url from FilesInfo a inner join FilesShare b on a. id=b.fileid where b.userid=5 and b.owner=1; +----+-------------------+-------------------------------------+ | id | name | url | +----+-------------------+-------------------------------------+ | 1 | dwnld_btn_1.png | C:\shareapp\admin\dwnld_btn_1.png | | 2 | dwnld_btn_1.png | C:\shareapp\admin\dwnld_btn_1.png | | 3 | dwnld_btn_1.png | C:\shareapp\admin\dwnld_btn_1.png | | 4 | dwnld_btn_1_1.png | C:\shareapp\admin\dwnld_btn_1_1.png | +----+-------------------+-------------------------------------+

<strong>i tried the following hql:</strong>

select a.id, a.name, a.url from FilesInfo a inner join FilesShare b where a.id=b.fileid and b.userid=5 and b.owner=1

<strong>but i am getting this error</strong>

<blockquote>

Path expected for join! [select a.id, a.name, a.url from app.domain.FilesInfo a inner join FilesShare b where a.id=b.fileid and b.userid=5 and b.owner=1]

</blockquote>

how to do inner join now, is the question

thankyou

Answer1:

Your query requires path, you can refer to this question for details: <a href="https://stackoverflow.com/questions/10448935/hql-error-path-expected-for-join" rel="nofollow">HQL ERROR: Path expected for join</a>.

So, something like this should resolve it:

select a.id, a.name, a.url from FilesInfo a inner join a.filesShared b where b.userid=5 and b.owner=1; <hr />

But I would just have a ManyToOne mapping in your FilesShare:

private FilesInfo filesInfo; @ManyToOne @JoinColumn(name = "id") public FilesInfo getFilesInfo() { return filesInfo; } public void setFilesInfo(FilesInfo filesInfo) { this.filesInfo = filesInfo; }

and do this query

from FilesShare where userId = 5 and owner = 1

It looks nicer and returns the list of file shares, each of them having parent (filesInfo) field populated.

Answer2:

Updated spring data version to 1.10.4.RELEASE and this solved the problem.

Recommend

  • springboot jackson returns array instead of proper json object
  • JSF property transfer from backing bean A to backing bean B
  • How can i POST json data in Android
  • Creating read-only (public) class members in C++
  • Can't access object in the array java
  • display Enum Values in UI with default value if not selected
  • JSF Lifecycle with immediate=true
  • @Embeddable and @EmbeddedId consists only of complex classes
  • Trouble in posting data as form data in Angular JS to Java REST web-service
  • Hibernate Composite Key: foreign key has wrong number of columns
  • Sign extending from a constant bit width in C#
  • Java library to map request parameters onto an object
  • Get Items in a PurchaseOrder using SuiteTalk
  • Extract JSON value in Bash [duplicate]
  • Getters and Setters in Eclipse for Hungarian Style Members
  • Spring creating bean but not injecting it
  • Conditionally ignore primitive typed fields with Jackson
  • Mapping ManyToMany with composite Primary key and Annotation:
  • How to extract a number from a string [duplicate]
  • Google Calendar Api is not showing event list
  • Using an enum contained in a Cloud Endpoint model on a Android client
  • How to get a list with description of all dba packages
  • Add dynamic data to line chart from mysql database with highcharts
  • Azure table store snapshot/backup capability
  • Bigquery event streaming and table creation
  • MYSQ & MVC3 SQL connection error \\ ProviderManifestToken but I am using MySQL
  • Using Sax parsing to edit and write XML in VB6
  • Moving mysql files across servers
  • Linq Objects Group By & Sum
  • Using $this when not in object context
  • Retrieving value from sql ExecuteScalar()
  • How to check if every primary key value is being referenced as foreign key in another table
  • Large data - storage and query
  • Circular dependency while pushing http interceptor
  • Comma separated Values
  • Linker errors when using intrinsic function via function pointer
  • KeystoneJS: Relationships in Admin UI not updating
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Checking variable from a different class in C#