gpt4 book ai didi

mysql - hibernate如何使用hql创建内部连接

转载 作者:行者123 更新时间:2023-11-29 06:49:47 24 4
gpt4 key购买 nike

我有两个由 onetomany 映射的实体类:

@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)

现在我正在尝试执行内部连接并获取 FilesInfo 类型的列表:

    @Override
public List<FilesInfo> reqSharedFiles(FilesShare fs) {
session=HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<FilesInfo> filesInfo = null;
filesInfo=session.createQuery("select a.id, a.name, a.url from FilesInfo as a
inner join FilesShare as b on "+
" a.id=b.fileId where b.userId= :userId and b.owner= :owner")
.setInteger("userId",fs.getUserId()).setInteger("owner",fs.getOwner()).list();
session.getTransaction().commit();
return filesInfo;
}

我收到这个错误

Struts has detected an unhandled exception: Messages:
org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr/RecognitionException;Lantlr/collections/impl/BitSet;)V File: org/hibernate/hql/antlr/HqlBaseParser.java Line number: 1,802 app.dao.UploadDAOImpl.reqSharedFiles(UploadDAOImpl.java:79) < ------ this line pointing to filesInfo=session.createQuery("select

请告诉我哪里错了?

谢谢

最佳答案

这是您使用的 hibernate 和 ANTLR jar 版本的问题。在 2.7.6 版之前,ANTLR Parser 类中没有 recover 方法?如果您使用的是早期版本的 ANTLR,例如 2.7.2,那么您会遇到问题。

SEE HERE

关于mysql - hibernate如何使用hql创建内部连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16248834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com