您好有以下实体;
@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
}
另一个
@Entity
public class FilesShare {
private Integer id;
private int userId;
private int owner;
}
结果和表格是:
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)
我想制作 hql,因为我制作了下面的 sql:
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;
给出以下输出:
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 |
+----+-------------------+-------------------------------------+
我尝试了以下 hql:
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
但我收到了这个错误
预计加入的路径![select a.id, a.name, a.url from app.domain.FilesInfo a 内部加入 FilesShare b where a.id=b.fileid and b.userid=5 and b.owner=1]
现在怎么做inner join,是个问题
谢谢你