Note that there are some explanatory texts on larger screens.

plurals
  1. POClassCast Exception in java
    primarykey
    data
    text
    <p>Iam writing a query in hibernate and my method is:</p> <pre><code>public String a(Object[] selectedAlarmId, Object[] selecteddeviceID, String loggedInUser, String clientIp, String role) throws Exception { int result = 0; b grp = new b(); try { Session hiberSession = HibernateSessionFactory.currentSession(); Transaction transaction = hiberSession.beginTransaction(); List deviceQueryList = null; String clauseAppender = ("select max(severity),devicenodeid from AlarmMappingBean where devicenodeid in (:devicelist) group by devicenodeid"); Query deviceQuery = hiberSession.createQuery(clauseAppender); deviceQuery.setParameterList("devicelist", selecteddeviceID); deviceQueryList = deviceQuery.list(); Iterator&lt;Object[]&gt; iter = deviceQueryList.iterator(); while(iter.hasNext()){ Object[] objAlarm = iter.next(); System.out.println(objAlarm.length); System.out.println("Severity - &gt; " + objAlarm[0]); System.out.println("Device Node ID - &gt; " + objAlarm[1]); Query updateMangedNode = hiberSession .createQuery("update ManagedNode set highestSeverity =? where nodeId = ?"); updateMangedNode.setParameter(0, objAlarm[0]); updateMangedNode.setParameter(1, Long.parseLong(objAlarm[1].toString())); //updateMangedNode.executeUpdate(); } // Long[] deviceArray =(Long[]) selecteddeviceID; Exception occurs here--&gt; Object[] devArray = (Long[]) selecteddeviceID; Query groupQuery = hiberSession .createQuery("select groupId from b where nodeId in (:devicelist)"); groupQuery.setParameterList("devicelist", devArray); List&lt;ManagedNode&gt; devicelist = new ArrayList&lt;ManagedNode&gt;(); devicelist = groupQuery.list(); if(!(devicelist.isEmpty() )){ Iterator&lt;ManagedNode&gt; itergroup =devicelist.iterator(); while(itergroup.hasNext()){ ManagedNode objgroup = itergroup.next(); grp.updateGroupHighestSeverity(objgroup.getGroupId()); } } transaction.commit(); } catch (Exception e) { e.printStackTrace(); throw e; } finally { HibernateSessionFactory.closeSession(); } return Integer.toString(result); } </code></pre> <p>Here the selecteddeviceId has values as [1234,12345, null, null] and query from the table b "select groupid from b where nodeid in(devicelist)" here datatype of groupid is int and nodeid is long</p> <blockquote> <p>It is giving me classcast exception as Ljava.lang.Object; cannot be cast to [Ljava.lang.Long;</p> </blockquote> <p>I am using <code>PostgresSQl</code></p> <p>Please help</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload