Выбор данных с параметрами из БД Postgres

Как реализовать выбор данных из БД с параметрами, когда параметры передаются из TextField?

Сейчас выбор и отображение происходит без параметров (т.е. выбираются все данные (пациенты))

Класс Patient:

@Entity
@Table(name = "patient")
public class Patient {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @Column(name = "fam")
    private String fam;
    @Column(name = "im")
    private String im;
    @Column(name = "ot")
    private String ot;
    @Column(name = "bdate")
    private Date bdate;
    @Column(name = "sex")
    private int sex;
    @Column(name = "phone")
    private String phone;
    @Column(name = "mail")
    private String mail;
    @Column(name = "snils")
    private String snils;
    @Column(name = "createdate")
    private Date createdate;

    public Patient() {

    }

    public Patient(String fam, String im, String ot, Date bdate, int sex, String phone, String mail, String snils, Date createdate) {
        this.fam = fam;
        this.im = im;
        this.ot = ot;
        this.bdate = bdate;
        this.sex = sex;
        this.phone = phone;
        this.mail = mail;
        this.snils = snils;
        this.createdate = createdate;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFam() {
        return fam;
    }

    public void setFam(String fam) {
        this.fam = fam;
    }

    public String getIm() {
        return im;
    }

    public void setIm(String im) {
        this.im = im;
    }

    public String getOt() {
        return ot;
    }

    public void setOt(String ot) {
        this.ot = ot;
    }

    public Date getBdate() {
        return bdate;
    }

    public void setBdate(Date bdate) {
        this.bdate = bdate;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getSnils() {
        return snils;
    }

    public void setSnils(String snils) {
        this.snils = snils;
    }

    public Date getCreatedate() {
        return createdate;
    }

    public void setCreatedate(Date createdate) {
        this.createdate = createdate;
    }
}

Класс PatientDao

public class PatientDao {

    public Patient findByID(int id) {
        return HibernateSessionFactoryUtil.getSessionFactory().openSession().get(Patient.class, id);
    }

    public void save(Patient patient) {
        Session session = HibernateSessionFactoryUtil.getSessionFactory().openSession();
        Transaction tx1 = session.beginTransaction();
        session.save(patient);
        tx1.commit();
        session.close();
    }

    //Метод для поиска всех пациентов
    public List<Patient> findAllPatients() {
        List<Patient> patientList = (List<Patient>) HibernateSessionFactoryUtil.getSessionFactory().openSession().createQuery("From Patient").list();
        return patientList;
    }
}

Класс PatientService

public class PatientService {

    private PatientDao patientDao = new PatientDao();

    private ObservableList<Patient> patients = FXCollections.observableArrayList();

    public PatientService() {

    }

    public void createPatient(Patient patient) {
        patientDao.save(patient);
    }

    public ObservableList<Patient> getPatients() {
        return patients;
    }

    public void fillPatientsList() {
        List<Patient> patientList = (List<Patient>) HibernateSessionFactoryUtil.getSessionFactory().openSession().createQuery("From Patient").list();
        patients.addAll(patientList);
    }
}

Класс MainController

public class MainController {

    private Stage mainStage;

    PatientService patientService = new PatientService();

    @FXML
    private TableView<Patient> tabPatient; //Грид для отображения пациентов
    @FXML
    private TableColumn<Patient, String> fieldPatFam; //Поле для грида пациентов
    @FXML
    private TableColumn<Patient, String> fieldPatIm;//Поле для грида пациентов
    @FXML
    private TableColumn<Patient, String> fieldPatOt;//Поле для грида пациентов
    @FXML
    private TableColumn<Patient, Date> fieldPatBdate;//Поле для грида пациентов

    public void setMainStage(Stage mainStage) {
        this.mainStage = mainStage;
    }

    public void initialize() {
        workPatientsGrid();
    }

    private void workPatientsGrid() {
        patientService.fillPatientsList();

        FilteredList<Patient> filteredList = new FilteredList<Patient>(patientService.getPatients(), patient -> true);

        patientService.getPatients().addListener(new ListChangeListener<Patient>() {
            @Override
            public void onChanged(Change<? extends Patient> c) {

            }
        });

        fieldPatFam.setCellValueFactory(new PropertyValueFactory<Patient, String>("fam"));
        fieldPatIm.setCellValueFactory(new PropertyValueFactory<Patient, String>("im"));
        fieldPatOt.setCellValueFactory(new PropertyValueFactory<Patient, String>("ot"));
        fieldPatBdate.setCellValueFactory(new PropertyValueFactory<Patient, Date>("bdate"));

        SortedList<Patient> sortedList = new SortedList<Patient>(filteredList);

        sortedList.comparatorProperty().bind(tabPatient.comparatorProperty());

        tabPatient.setItems(sortedList);
    }

    public void onCreatePatient(ActionEvent actionEvent) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/create_patient.fxml"));
        Scene scene = new Scene(root);
        Stage stage = new Stage();
        stage.setScene(scene);
        stage.show();
    }

    public void onSearchPatient(ActionEvent actionEvent) {
    }
}

Ответы (0 шт):