有 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();
}