简体   繁体   English

错误util.JDBCExceptionReporter-使用Hibernate ORM未为参数1指定值

[英]ERROR util.JDBCExceptionReporter - No value specified for parameter 1 using Hibernate ORM

Below are my POJO's 以下是我的POJO的

class User extends AbstractDomainObject{
    private String username;
    private String password;

    //setter and getter
}

class Notification extends AbstractDomainObject{
    private String message;
    private Set<User> notificationFor;

    //setter and getter
}

class AbstractDomainObject{
    private long id;
    // setter and getter
}

Below are mapping's for above POJO 以下是以上POJO的映射

User.hbm.xml User.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="User" table="user">
        <id name="id" type="long" column="id">
            <generator class="native" />
        </id>

            <property name="username" type="string">
            <column name="username" />
        </property>

        <property name="password" type="string">
            <column name="password" />
        </property>
    </class>
 </hibernate-mapping>

Notification.hbm.xml Notification.hbm.xml

 <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>

         <class name="Notification" table="notification">
            <id name="id" type="long" column="id">
                <generator class="native" />
            </id>

                <set name="notificationFor" table="user_notification" lazy="false" cascade="all">
            <key column="notification_id"/>
            <many-to-many unique="true" class="User" column="user_id"/>
            </set>

                <property name="message" type="string">
            <column name="message" />
            </property>
         </class>
    </hibernate-mapping>

I want list of notifications for given user. 我想要给定用户的通知列表。 below is my daoimpl. 下面是我的daoimpl。

public List<Notification> getNotification(User user) {

        Session session = null;
        List<Notification> notifications = null;
        try {

            session = getSessionFactory().openSession();
            String queryString = "from Notification notification where notification.notificationFor IN (:user)";
            Query query = session.createQuery(queryString);
            query.setParameter("user", user);
            notifications = query.list();        

        } catch (Exception e) {

            e.printStackTrace();

        }

        return notifications;
    }

Above code snippet giving error at query.list() line. 上面的代码段在query.list()行给出了错误。 Error is ERROR util.JDBCExceptionReporter - No value specified for parameter 1 Any help will be appreciable. 错误为ERROR util.JDBCExceptionReporter-未为参数1指定值任何帮助都将是可观的。 I don't know where I am wrong. 我不知道我哪里错了。

User is a user defined class which hibernate do not know about it. 用户是一个用户定义的类,它不休眠。 You should supply a type which is known by Hibernate. 您应该提供一种Hibernate已知的类型。 It may be String , Long , int . 可能是StringLongint

I assume that User has a name field and the query will be performed accordingly. 我假设用户有一个名称字段,查询将相应地执行。

query.setParameter("user", user.getName());

Furthermore, you should give the entity class to Query class. 此外,您应该将实体类赋予Query类。 Query#setResultTransformer can be used. 可以使用Query#setResultTransformer

Query query = session.createQuery(queryString).setResultTransformer(Transformers.aliasToBean(Notification.class));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hibernate和DB2-在插入表中或从表中删除时发出错误:util.JDBCExceptionReporter - Hibernate and DB2- gives out an ERROR: util.JDBCExceptionReporter while inserting into or deleting from the table Hibernate,错误org.hibernate.util.JDBCExceptionReporter字段“ Variable_ID”没有默认值 - Hibernate, error org.hibernate.util.JDBCExceptionReporter Field 'Variable_ID' doesn't have a default value 错误org.hibernate.util.JDBCExceptionReporter-数据列“类型”被截断 - ERROR org.hibernate.util.JDBCExceptionReporter - Data truncated for column 'type' 错误org.hibernate.util.JDBCExceptionReporter-通信链接失败 - ERROR org.hibernate.util.JDBCExceptionReporter - Communications link failure SQL 错误:17059,SQLState:99999:org.hibernate.util.JDBCExceptionReporter-[ERROR]:无法转换为内部表示 - SQL Error: 17059, SQLState: 99999:org.hibernate.util.JDBCExceptionReporter-[ERROR]: Fail to convert to internal representation 错误:org.hibernate.util.JDBCExceptionReporter - 无法加载JDBC驱动程序类&#39;com.mysql.jdbcDriver&#39; - ERROR: org.hibernate.util.JDBCExceptionReporter - Cannot load JDBC driver class 'com.mysql.jdbcDriver' 获取 org.hibernate.util.JDBCExceptionReporter: Connection reset by peer: socket write error - Getting org.hibernate.util.JDBCExceptionReporter: Connection reset by peer: socket write error 了解Hibernate:JDBCExceptionReporter | 无效的参数索引 - Understanding Hibernate: JDBCExceptionReporter | Invalid parameter index org.hibernate.util.JDBCExceptionReporter-“字段列表”中的未知列“ postalCode” - org.hibernate.util.JDBCExceptionReporter - Unknown column 'postalCode' in 'field list' 错误 org.hibernate.util.JDBCExceptionReporter - ORA-02291:违反完整性约束 (PERFMGMT.ZAUTOMATION_PHASE_FK1) - 未找到父键 - ERROR org.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (PERFMGMT.ZAUTOMATION_PHASE_FK1) violated - parent key not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM