我对Hibernate和find的方法有点问题。 有我的代码:
private void Delete(){
try {
int result = JOptionPane.showConfirmDialog(null, "Êtes vous sur ?", "Confirmer", JOptionPane.YES_NO_OPTION);
if(result==JOptionPane.YES_OPTION){
int index = this.jTableLocataire.getSelectedRow();
System.out.println(index);
String id = this.jTableLocataire.getValueAt(index, 0).toString();
System.out.println(id);
Locataire locataire = this.locataireModel.find(id);
System.out.println(locataire);
this.locataireModel.delete(locataire);
FillData();
//this.jTextFieldNom.setText(locataire.getNom());
//this.jTextFieldPrenom.setText(locataire.getPrenom());
//this.jTextFieldAdresse.setText(locataire.getAdresse());
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
第一个System.out.println(id)向我发回预期值。但是,System.out.println(locataire)将我发回null,因为方法find(id)找不到。
在这里,我不明白,因为id变量中的预期值已经存在于我的表中!!
为了证明这一点,如果我做(我传递我想要手动删除的行的id的值)就像那样:
Locataire locataire = this.locataireModel.find(16);
因此该行被删除。 这是合乎逻辑的,因为我把一个已经存在于我的表中的id。
那么,为什么方法find()在id存在的时候发回给我?
https://ufile.io/dmwie我在zip中的完整项目