title: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to university.pojo.Schedule
body: <p>There are some similar questions, but none of them could help me.
  I tried to fill a JTable with data from a DB using hybernate and everething was ok when I extracted information from a single table, but when I tried to do the same with joined tables I started getting an exception.
  This are some of my pojo and mapping files(they are generated by NetBeans)</p>
  
  <pre><code>public class Schedule  implements java.io.Serializable {
       private Integer scheduleId;
       private Days days;
       private Groups groups;
       private Lessons lessons;
       private Rooms rooms;
       private Teachers teachers;
       //constructors, getters and setters
     }
  
  public class Groups  implements java.io.Serializable {
       private Integer groupId;
       private String groupName;
       private Set schedules = new HashSet(0);
       //constructors, getters and setters
     }
  
  &lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- Generated 03.10.2015 17:16:15 by Hibernate Tools 4.3.1 --&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="university.pojo.Schedule" table="schedule" catalog="university" optimistic-lock="version"&gt;
          &lt;id name="scheduleId" type="java.lang.Integer"&gt;
              &lt;column name="schedule_id" /&gt;
              &lt;generator class="identity" /&gt;
          &lt;/id&gt;
          &lt;many-to-one name="days" class="university.pojo.Days" fetch="select"&gt;
              &lt;column name="day_id" not-null="true" /&gt;
          &lt;/many-to-one&gt;
          &lt;many-to-one name="groups" class="university.pojo.Groups" fetch="select"&gt;
              &lt;column name="group_id" not-null="true" /&gt;
          &lt;/many-to-one&gt;
          &lt;many-to-one name="lessons" class="university.pojo.Lessons" fetch="select"&gt;
              &lt;column name="lesson_id" not-null="true" /&gt;
          &lt;/many-to-one&gt;
          &lt;many-to-one name="rooms" class="university.pojo.Rooms" fetch="select"&gt;
              &lt;column name="room_id" not-null="true" /&gt;
          &lt;/many-to-one&gt;
          &lt;many-to-one name="teachers" class="university.pojo.Teachers" fetch="select"&gt;
              &lt;column name="teacher_id" not-null="true" /&gt;
          &lt;/many-to-one&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  
  &lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  &lt;!-- Generated 03.10.2015 17:16:15 by Hibernate Tools 4.3.1 --&gt;
  &lt;hibernate-mapping&gt;
      &lt;class name="university.pojo.Groups" table="groups" catalog="university" optimistic-lock="version"&gt;
          &lt;id name="groupId" type="java.lang.Integer"&gt;
              &lt;column name="group_id" /&gt;
              &lt;generator class="identity" /&gt;
          &lt;/id&gt;
          &lt;property name="groupName" type="string"&gt;
              &lt;column name="group_name" length="100" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;set name="schedules" table="schedule" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="group_id" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="university.pojo.Schedule" /&gt;
          &lt;/set&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>And this is the main part</p>
  
  <pre><code>package university.ui;
  
  import java.util.List;
  import java.util.Vector;
  import javax.swing.table.DefaultTableModel;
  import org.hibernate.HibernateException;
  import org.hibernate.Query;
  import org.hibernate.Session;
  import university.pojo.Schedule;
  import university.pojo.Teachers;
  import university.util.HibernateUtil;
  
  public class uni extends javax.swing.JFrame {
      public uni() {
          initComponents();
      }
  
      private static String QUERY_FOR_TEACHER="from Teachers t where t.teacherName like '";
      private static String QUERY_FOR_TEACHER_SCHEDULE="from Schedule sd "
              + "join sd.lessons sdl "
              + "join sd.rooms sdr "
              + "join sd.groups sdg "
              + "join sd.teachers sdt "
              + "join sd.days sdd "
              + "where sdd.dayName like '";
  
      private void runQueryForTeacherSchedule(){
          executeHQLQuery(QUERY_FOR_TEACHER_SCHEDULE + "mondey" + "' "
                  + "and sdt.teacherName like '" + "bruce" + "'",2);
      }
  
      private void runQueryBasedOnTeacherName() {
          executeHQLQuery(QUERY_FOR_TEACHER + enterTeacherName.getText() + "%'",1);
      }
      private void executeHQLQuery(String hql, int sc) {
          try {
              Session session = HibernateUtil.getSessionFactory().openSession();
              session.beginTransaction();
              Query q = session.createQuery(hql);
              List resultList = q.list();
              switch(sc){
                  //displayResult(resultList,sc);
                  case 1: displayResult1(resultList);
                      break;
                  case 2: displayResult2(resultList);
                      break;
              }
              session.getTransaction().commit();
          } catch (HibernateException he) {
              he.printStackTrace();
          }
      }
  
      private void displayResult1(List resultList) {
          Vector&lt;String&gt; tableHeaders = new Vector&lt;String&gt;();
          Vector tableData = new Vector();
          tableHeaders.add("Names"); 
          for(Object o : resultList) {
              Teachers teachers = (Teachers)o;
              Vector&lt;Object&gt; oneRow = new Vector&lt;&gt;();
              oneRow.add(teachers.getTeacherName());
              tableData.add(oneRow);
          }
          teacherNameTable.setModel(new DefaultTableModel(tableData, tableHeaders));
      }
  
      private void displayResult2(List resultList) {
          Vector&lt;String&gt; tableHeaders = new Vector&lt;String&gt;();
          Vector tableData = new Vector();
          //tableHeaders.add("Room");
          tableHeaders.add("Group");
          //tableHeaders.add("Start");
          //tableHeaders.add("End");
          for(Object o : resultList) {
              Schedule schedule = (Schedule)o;
              Vector&lt;Object&gt; oneRow = new Vector&lt;&gt;();
              //oneRow.add(schedule.getRooms().getRoomNumber());
              oneRow.add(schedule.getGroups().getGroupName());                        
              //oneRow.add(schedule.getLessons().getLessonStart());                        
              //oneRow.add(schedule.getLessons().getLessonEnd());
              tableData.add(oneRow);
          }
          teacherScheduleTable.setModel(new DefaultTableModel(tableData, tableHeaders));                    
      }
  
      @SuppressWarnings("unchecked")
      // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
      private void initComponents() {
  
          jTabbedPane2 = new javax.swing.JTabbedPane();
          jPanel4 = new javax.swing.JPanel();
          enterTeacherName = new javax.swing.JTextField();
          jScrollPane3 = new javax.swing.JScrollPane();
          teacherNameTable = new javax.swing.JTable();
          teacherWorkDay = new javax.swing.JComboBox();
          jScrollPane4 = new javax.swing.JScrollPane();
          teacherScheduleTable = new javax.swing.JTable();
          jPanel5 = new javax.swing.JPanel();
          jScrollPane1 = new javax.swing.JScrollPane();
          jTable1 = new javax.swing.JTable();
          jScrollPane2 = new javax.swing.JScrollPane();
          jTable2 = new javax.swing.JTable();
          jPanel6 = new javax.swing.JPanel();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
          enterTeacherName.addCaretListener(new javax.swing.event.CaretListener() {
              public void caretUpdate(javax.swing.event.CaretEvent evt) {
                  enterTeacherNameCaretUpdate(evt);
              }
          });
  
          teacherNameTable.setModel(new javax.swing.table.DefaultTableModel(
              new Object [][] {
                  {null},
                  {null},
                  {null},
                  {null}
              },
              new String [] {
                  "Names"
              }
          ));
          /*
          teacherNameTable.addMouseListener(new MouseAdapter() {
              @Override
              public void mouseClicked(final MouseEvent e) {
                  if (e.getClickCount() == 1) {
                      final JTable target = (JTable)e.getSource();
                      final int row = target.getSelectedRow();
                      final int column = target.getSelectedColumn();
                      // Cast to ur Object type
                      String urObjctInCell = (String)target.getValueAt(row, column);
  
                  }
  
              }
  
          });
          */
          teacherNameTable.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent evt) {
                  teacherNameTableMouseClicked(evt);
              }
          });
          jScrollPane3.setViewportView(teacherNameTable);
  
          teacherWorkDay.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "mondey", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday" }));
  
          teacherScheduleTable.setModel(new javax.swing.table.DefaultTableModel(
              new Object [][] {
                  {null, null, null, null},
                  {null, null, null, null},
                  {null, null, null, null},
                  {null, null, null, null}
              },
              new String [] {
                  "Room", "Group", "Start", "End"
              }
          ));
          jScrollPane4.setViewportView(teacherScheduleTable);
  
          javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
          jPanel4.setLayout(jPanel4Layout);
          jPanel4Layout.setHorizontalGroup(
              jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel4Layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                      .addComponent(enterTeacherName, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                      .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(jPanel4Layout.createSequentialGroup()
                          .addComponent(teacherWorkDay, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                          .addGap(0, 0, Short.MAX_VALUE))
                      .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE))
                  .addContainerGap())
          );
          jPanel4Layout.setVerticalGroup(
              jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel4Layout.createSequentialGroup()
                  .addContainerGap()
                  .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                      .addComponent(enterTeacherName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(teacherWorkDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
                      .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                  .addContainerGap())
          );
  
          jTabbedPane2.addTab("Teachers", jPanel4);
  
          jTable1.setModel(new javax.swing.table.DefaultTableModel(
              new Object [][] {
                  {null},
                  {null},
                  {null},
                  {null}
              },
              new String [] {
                  "Title 1"
              }
          ));
          jScrollPane1.setViewportView(jTable1);
  
          jTable2.setModel(new javax.swing.table.DefaultTableModel(
              new Object [][] {
                  {null},
                  {null},
                  {null},
                  {null}
              },
              new String [] {
                  "Title 1"
              }
          ));
          jScrollPane2.setViewportView(jTable2);
  
          javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
          jPanel5.setLayout(jPanel5Layout);
          jPanel5Layout.setHorizontalGroup(
              jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jPanel5Layout.createSequentialGroup()
                  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(0, 345, Short.MAX_VALUE))
          );
          jPanel5Layout.setVerticalGroup(
              jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jScrollPane1)
              .addComponent(jScrollPane2)
          );
  
          jTabbedPane2.addTab("tab2", jPanel5);
  
          javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
          jPanel6.setLayout(jPanel6Layout);
          jPanel6Layout.setHorizontalGroup(
              jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 555, Short.MAX_VALUE)
          );
          jPanel6Layout.setVerticalGroup(
              jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 427, Short.MAX_VALUE)
          );
  
          jTabbedPane2.addTab("tab3", jPanel6);
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jTabbedPane2)
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jTabbedPane2)
          );
  
          pack();
      }// &lt;/editor-fold&gt;                        
  
      private void enterTeacherNameCaretUpdate(javax.swing.event.CaretEvent evt) {                                             
          runQueryBasedOnTeacherName();
  
      }                                            
  
      private void teacherNameTableMouseClicked(java.awt.event.MouseEvent evt) {                                              
          // TODO add your handling code here:
          //int row=teacherNameTable.getSelectedRow();
          //String tableClick=(teacherNameTable.getModel().getValueAt(row, 0).toString());
          runQueryForTeacherSchedule();
      }                                             
  /**/
      /**
       * @param args the command line arguments
       */
      public static void main(String args[]) {
          /* Set the Nimbus look and feel */
          //&lt;editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "&gt;
          /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
           * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
           */
          try {
              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                  if ("Nimbus".equals(info.getName())) {
                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
                      break;
                  }
              }
          } catch (ClassNotFoundException ex) {
              java.util.logging.Logger.getLogger(uni.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (InstantiationException ex) {
              java.util.logging.Logger.getLogger(uni.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex) {
              java.util.logging.Logger.getLogger(uni.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
              java.util.logging.Logger.getLogger(uni.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          }
          //&lt;/editor-fold&gt;
  
          /* Create and display the form */
          java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  new uni().setVisible(true);
              }
          });
      }
  
      // Variables declaration - do not modify                     
      private javax.swing.JTextField enterTeacherName;
      private javax.swing.JPanel jPanel4;
      private javax.swing.JPanel jPanel5;
      private javax.swing.JPanel jPanel6;
      private javax.swing.JScrollPane jScrollPane1;
      private javax.swing.JScrollPane jScrollPane2;
      private javax.swing.JScrollPane jScrollPane3;
      private javax.swing.JScrollPane jScrollPane4;
      private javax.swing.JTabbedPane jTabbedPane2;
      private javax.swing.JTable jTable1;
      private javax.swing.JTable jTable2;
      private javax.swing.JTable teacherNameTable;
      private javax.swing.JTable teacherScheduleTable;
      private javax.swing.JComboBox teacherWorkDay;
      // End of variables declaration                   
  }
  </code></pre>
  
  <p>I used this tutuorial as a guidline for writing my program, changing it were necessary.
  <a href="https://netbeans.org/kb/docs/java/hibernate-java-se.html" rel="nofollow">https://netbeans.org/kb/docs/java/hibernate-java-se.html</a></p>
  
  <p>This is the exact exception message</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to university.pojo.Schedule
      at university.ui.uni.displayResult2(uni.java:74)
      at university.ui.uni.executeHQLQuery(uni.java:44)
      at university.ui.uni.runQueryForTeacherSchedule(uni.java:28)
      at university.ui.uni.teacherNameTableMouseClicked(uni.java:275)
      at university.ui.uni.access$100(uni.java:13)
      at university.ui.uni$2.mouseClicked(uni.java:142)
      at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
      at java.awt.Component.processMouseEvent(Component.java:6528)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3322)
      at java.awt.Component.processEvent(Component.java:6290)
      at java.awt.Container.processEvent(Container.java:2234)
      at java.awt.Component.dispatchEventImpl(Component.java:4881)
      at java.awt.Container.dispatchEventImpl(Container.java:2292)
      at java.awt.Component.dispatchEvent(Component.java:4703)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4542)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
      at java.awt.Container.dispatchEventImpl(Container.java:2278)
      at java.awt.Window.dispatchEventImpl(Window.java:2739)
      at java.awt.Component.dispatchEvent(Component.java:4703)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751)
      at java.awt.EventQueue.access$500(EventQueue.java:97)
      at java.awt.EventQueue$3.run(EventQueue.java:702)
      at java.awt.EventQueue$3.run(EventQueue.java:696)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
      at java.awt.EventQueue$4.run(EventQueue.java:724)
      at java.awt.EventQueue$4.run(EventQueue.java:722)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:721)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
  </code></pre>