0

有 2 jComboBox.. 和 2 Class 。当表单加载事件时,它将填充jComboBox1,当ActionEvent触发时,它将加载另一个类并选择 jComboBox1。

我想从方法中获取 PersonelID,jComboBox.GetSelectItem而不是用这个 id 调用另一个类。但是遇到这个错误;

    Exception in thread "AWT-EventQueue-0" 
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: 
could not get a field value by reflection getter of DBClasses.Unvan.unvanID

这是我的代码。

 private void UnvanAl()
{
if (jComboBox1.getSelectedItem() != null) {
         EntityManagerFactory emf = Persistence.createEntityManagerFactory("SwingDenemePU");
    EntityManager em = emf.createEntityManager();
    Query sorgu = em.createQuery("select p from Personel p where p.unvanID = :id");
    int id = ((Unvan)jComboBox1.getSelectedItem()).getUnvanID();

    sorgu.setParameter("id", id);
    personelList = sorgu.getResultList();
    Object[] items = new Object[personelList.size()];
    for (int i = 0; i < personelList.size(); i++) {
        Personel personel = personelList.get(i);
        items[i]=personel.getPersonelAdSoyad();

    }

    DefaultComboBoxModel def = new DefaultComboBoxModel(items);
    jComboBox2.setModel(def);
    }

}


private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
   UnvanAl();

}
4

1 回答 1

0

你有属性“unvanID”的getter/setter吗?

于 2009-07-02T20:53:22.997 回答