删除表中的行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();
}
1条答案
按热度按时间xghobddn1#
或通过标识符删除,并通过实体立即删除