Reputation: 2483
I have two classes Task and TaskComponents. TaskComponents contains a task mapped by a Task_ID. I am trying to select a task joined to the TaskComponents table. I have tried many different SQL statements but all of them come back with QuerySyntaxException Path Expected to join.
Task POJO
@Entity
@Table(name = "task")
public class Task implements Serializable {
@Id
@Column(name = "ID")
private int Id;
@Column(name = "Name")
private String name;
@Column(name = "Description")
private String description;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Site_ID")
private Site site;
public int getId() {
return Id;
}
public void setId(int Id) {
this.Id = Id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Site getSite() {
return site;
}
public void setSite(Site site) {
this.site = site;
}
}
TaskComponents POJO
@Entity
@Table(name = "taskcomponents")
public class TaskComponents implements Serializable {
@Id
@Column(name = "ID")
private int Id;
@Column(name = "VersionName")
private String versionName;
@Column(name = "Live", nullable = false)
@Type(type = "org.hibernate.type.NumericBooleanType")
private boolean live;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Task_ID")
private Task task;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "Group_ID")
private GroupDB group;
public int getId() {
return Id;
}
public void setId(int Id) {
this.Id = Id;
}
public String getVersionName() {
return versionName;
}
public void setVersionName(String versionName) {
this.versionName = versionName;
}
public boolean isLive() {
return live;
}
public void setLive(boolean live) {
this.live = live;
}
public Task getTask() {
return task;
}
public void setTask(Task task) {
this.task = task;
}
public GroupDB getGroup() {
return group;
}
public void setGroup(GroupDB group) {
this.group = group;
}
}
And my attempted queries.
Query query = session.createQuery("SELECT t FROM Task t INNER JOIN TaskComponents tc ON t.Id=tc.task.Id");
Query query = session.createQuery("SELECT t FROM Task t INNER JOIN TaskComponents tc ON t=tc.task");
Upvotes: 0
Views: 49
Reputation: 28559
You shouldn't use explicitely ON to define the join, Hibernate will infer it from the mapping, just write you query as
SELECT tc.task FROM TaskComponents tc INNER JOIN tc.task
this is what is referred to behind your error message Path expected for join
the query expects a property defined path from one entity to another
Upvotes: 1