HQL:命名参数即使存在也找不到

HQL : Named Parameter not found even if it exist

我收到无法定位命名参数的异常,即使它存在。

org.hibernate.QueryParameterException: could not locate named parameter [type]

查询

String query = ("insert into my_table (abc_id, dup_id,type_code) "+
                     " (abc_seq.nextval, 2,:type");
            Query myQuery = em.createNativeQuery(query);    
            nativeQuery.setParameter("type", code);

我根本不明白这是什么问题。

您的查询缺少括号和 values 关键字。

尝试

String query = ("insert into my_table (abc_id, dup_id,type_code) "+
                "values (abc_seq.nextval, 2,:type)");
Query myQuery = em.createNativeQuery(query);    
nativeQuery.setParameter("type", code);