Note that there are some explanatory texts on larger screens.

plurals
  1. POException java.lang.ClassCastException
    primarykey
    data
    text
    <p>I am trying to read only two column (One is Integer and other is String) from the table and get a list of the result. I am reading the table using <code>EntityManger</code> as shown in the code below. This code executes correctly and no Exception comes.</p> <pre><code>@SuppressWarnings("unchecked") public List&lt;BusinessProcessIdAndName&gt; getBusinessProcessList(int level) { List&lt;BusinessProcessIdAndName&gt; businessProcessTableList = new ArrayList&lt;BusinessProcessIdAndName&gt;(); EntityManager em = null; try { EntityManagerFactory emf = Persistence.createEntityManagerFactory(ApplicationConstants.DERBY_PERSISTENCE_UNIT_NAME); em = emf.createEntityManager(); EntityTransaction et = em.getTransaction(); et.begin(); Query query = em.createQuery("select t.businessProcessId, t.businessProcessName from BusinessProcessTable t"); businessProcessTableList = query.getResultList(); // The line below displays the correct result, The logger is basically a System.out.println logger.debug(businessProcessTableList.size()); } catch(Exception e) { logger.debug("Exception Caught while getting BP List: " + e); } return businessProcessTableList; } </code></pre> <p><code>BusinessProcessIdAndName</code> class is as below</p> <pre><code>public class BusinessProcessIdAndName { private Integer businessProcessId; private String businessProcessName; public Integer getBusinessProcessId() { return businessProcessId; } public void setBusinessProcessId(Integer businessProcessId) { this.businessProcessId = businessProcessId; } public String getBusinessProcessName() { return businessProcessName; } public void setBusinessProcessName(String businessProcessName) { this.businessProcessName = businessProcessName; } } </code></pre> <p>Then in Managed Bean I am using the result of the above code as below. Here I get the Exception </p> <blockquote> <p>java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.ewt.ewtalmutil.object.BusinessProcessIdAndName</p> </blockquote> <p>I know this Exception says that there is a mismatch in the object and they are incompatible, But I think my objects should be compatible, please tell me where I am wrong and what is the correct way to do it.</p> <pre><code>public SelectCriteriaBean () { logger.entering(CLASS_NAME); this.businessProcessLevelZeroList = new ArrayList&lt;SelectItem&gt;(); List&lt;BusinessProcessIdAndName&gt; tempBusinessProcessLevelZeroList = new BusinessProcessTableManager().getBusinessProcessList(0); // The line below also displays correct result logger.debug(tempBusinessProcessLevelZeroList.size()); // The line below gives Exception: java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.ewt.ewtalmutil.object.BusinessProcessIdAndName try { Iterator&lt;BusinessProcessIdAndName&gt; iterator = tempBusinessProcessLevelZeroList.iterator(); } catch (Exception e) { logger.debug("Exception: " + e); } while (iterator.hasNext()) { BusinessProcessIdAndName businessProcessIdAndName = new BusinessProcessIdAndName(); businessProcessIdAndName = iterator.next(); // The Exception/Error comes in the line below String businessProcessName = businessProcessIdAndName.getBusinessProcessName(); int businessProcessId = businessProcessIdAndName.getBusinessProcessId(); String businessProcessIdString = String.valueOf(businessProcessId); SelectItem item = new SelectItem(businessProcessIdString,businessProcessName); businessProcessLevelZeroList.add(item); } setBusinessProcessLevelOneListRendered(false); setAddBusinessProcessRendered(false); logger.exiting(CLASS_NAME); } </code></pre>
    singulars
    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.
 

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