1

我有两个由 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 检测到一个未处理的异常: 消息:
org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr/RecognitionException;Lantlr/collections/impl/BitSet;)V 文件:org/hibernate/hql/antlr/HqlBaseParser.java 行号: 1,802 app.dao.UploadDAOImpl.reqSharedFiles(UploadDAOImpl.java:79) < ------ 这一行指向 filesInfo=session.createQuery("select

请告诉我哪里错了?

谢谢

4

1 回答 1

2

这是您使用的休眠和 ANTLR jar 版本的问题。在 2.7.6 版之前,ANTLR Parser 类中不存在恢复方法?如果您使用的是早期版本的 ANTLR,例如 2.7.2,那么您会遇到问题。

看这里

于 2013-04-27T06:17:40.870 回答