小编Ash*_*nna的帖子

java.sql.SQLException:参数索引超出范围(3>参数个数,即2)

我有一个表"AuthorFollow",它具有'authorId'和'userId'的复合键,它们分别是"AuthorInfo"和"UserInfo"表中的主键.

我试图在数据库中保存"AuthorFollow"的对象(我正在使用mysql).但是,我收到了错误:

org.hibernate.exception.GenericJDBCException: could not insert: [com.pojo.hibernate.AuthorFollow]
.
.
.
Caused by: java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
.
.
.
Run Code Online (Sandbox Code Playgroud)

我正在尝试保存对象的代码是:

Transaction transaction = hibernateTemplate.getSessionFactory().getCurrentSession().beginTransaction();
    try {
        AuthorFollow authorFollow = new AuthorFollow();
        authorFollow.setAuthorId(authorInfo.getAuthorId());
        authorFollow.setUserId(userInfo.getUserId());
        authorFollow.setAuthorInfoByAuthorId(authorInfo);
        authorFollow.setUserInfoByUserId(userInfo);

        authorInfo.getAuthorFollowsByAuthorId().add(authorFollow);
        userInfo.getAuthorFollowsByUserId().add(authorFollow);

        updateObject(authorInfo);
        updateObject(userInfo);

        transaction.commit();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        transaction.rollback();
        return false;
    }
Run Code Online (Sandbox Code Playgroud)

映射文件(这些映射由IntellijIdea自动生成):AuthorFollow.hbm.xml:

<hibernate-mapping>
    <class name="com.pojo.hibernate.AuthorFollow" table="author_follow" catalog="book">
    <composite-id mapped="true" class="com.pojo.hibernate.AuthorFollowPK">
        <key-property name="userId" column="user_id"/>
        <key-property name="authorId" column="author_id"/>
    </composite-id>
    <many-to-one name="authorInfoByAuthorId" …
Run Code Online (Sandbox Code Playgroud)

hibernate hibernate-mapping

7
推荐指数
1
解决办法
4496
查看次数

备份和恢复主屏幕小部件和动态壁纸

我的客户希望我创建一个应用程序,它将安装一些应用程序,第三方启动器,主屏幕中的一些小部件和动态壁纸.所有这些都是用户交互最少的.这样他就可以通过安装一个应用程序来复制多个设备中的所有设置.

安装应用程序部分已完成,启动程序的备份也已恢复.但是,它无法恢复在主设备上设置的小部件.同样的动态壁纸.我搜索了两个问题的解决方案,但我找不到它.有什么办法吗?

设备将被植根,因此您还可以建议需要root的解决方案.

android android-widget live-wallpaper android-backup-service

5
推荐指数
0
解决办法
534
查看次数