我收到此错误
线程中的异常" main" java.lang.ClassCastException: [Ljava.lang.Object;无法转换为xxx.xxx.xxx.Terminal
当我尝试这段代码时;那有什么不对?
for(int k=0;k<argTerminal.length;k++){
String hql = "select crimpkontakt from Terminal where id="+argTerminal[k];
Query query = session.createQuery(hql);
query.setMaxResults(1);
Terminal nameTerminal = (Terminal) query.uniqueResult();
答案 0 :(得分:-1)
如果要选择终端对象,您的HQL应如下所示:
String hql = "from Terminal where id="+argTerminal[k]
另外,为了避免使用参数API注入,API是首选选项:
Query query = session.createQuery("select from Terminal where id = :id");
query.setString("id", argTerminal[k]); // I assume that id is a String here
query.setMaxResults(1);
如果id
是主键,则可以使用session.get(Terminal.class, argTerminal[k])