jComboBox给出了org.hibernate.PropertyAccessException错误

时间:2009-07-02 20:43:56

标签: java swing jcombobox

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

我想从jComboBox.GetSelectItem方法获取PersonelID,而不是使用此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();

}

1 个答案:

答案 0 :(得分:0)

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