删除表中的一行delete(id) - id突出显示红色(…无法应用于(javafx.scene.control.TableColumn) 我想从数据库表中删除一行。
//delete button
button_del.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseEvent -> {
int selectedIndex = tableView_tableAll.getSelectionModel().getSelectedIndex();
if (selectedIndex >= 0) {
// tableView_tableAll.getItems().remove(selectedIndex);
delete(id);
} else {
// Nothing selected
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Ошибка");
alert.setHeaderText("No row selected for deletion");
alert.setContentText("Select row in table");
alert.showAndWait();
}
});
}
}
private void delete(Integer id ) {
Session session = utils.HibernateSessionFactory.getSessionFactory().openSession();
session.beginTransaction();
ProductEntity productEntity =(ProductEntity) session.get(ProductEntity.class,id);
session.delete(productEntity);
session.getTransaction().commit();
session.close();
}
最佳答案
ProductEntity selectedItem = tableView_tableAll.getSelectionModel().getSelectedItem();
delete(selectedItem.getId());
或者通过标识符删除删除并通过实体立即删除
private void delete(ProductEntity entity)
...
ProductEntity selectedItem = tableView_tableAll.getSelectionModel().getSelectedItem();
delete(selectedItem);
关于mysql - 删除表中的一行 mysql hiberhate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50310821/