Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with getting query result from database
    primarykey
    data
    text
    <p>I made a class called <code>SpecializationBean</code> which has two private fields:</p> <pre><code>private ArrayList&lt;SelectItem&gt; specializationItems= new ArrayList&lt;SelectItem&gt;(); private String specializationName; </code></pre> <p>I have ofcourse a getter and setter for those two.</p> <p>and a <code>buildSpecializationList</code> method which builds the <code>specializationItems</code> list: (I call this method in the getter):</p> <pre><code>public void buildSpecializationList(){ List&lt;Object[]&gt; specializations = null; try{ Session mySession = HibernateUtil.getAdmSessionFactory().getCurrentSession(); Transaction transaction = mySession.beginTransaction(); String sql = "SELECT J_Specialization_ID, Specialization_Name_Ar FROM J_Specialization WHERE J_Department_ID = '1000001'"; Query query = mySession.createSQLQuery(sql).addScalar("id", Hibernate.LONG).addScalar("name", Hibernate.STRING); specializations = query.list(); } catch(Exception e){ e.printStackTrace(); } this.specializationItems = new ArrayList&lt;SelectItem&gt;(90); for(Object[] sp: specializations ){ this.specializationItems.add(new SelectItem(sp[0],(String) sp[1])); } } </code></pre> <p>The problem is that I get a null pointer exception which shows that the list <code>specializations</code> (defined in the <code>buildSpecializationList()</code>) is null. I have tried the query myself on the table and it returns a result. I also tried HQL query (istead):</p> <pre><code>String sqlQuery = "Select JSpecializationId, specializationNameAr FROM JSpecializationWHERE JDepartmentId = '1000001'"; Query q = mySession.createQuery(sqlQuery); </code></pre> <p>But still, I get a null pointer exception which shows that the query returns me null result. Do you have any suggestions?</p>
    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.
    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