Issue
In my JavaFx project I use Hibernate to connect to a local Postgresql database. In Intellij the project runs and the connection works. Also when I start the formed jar from the console everything works and the data can be read. However when I start the jar from the explorer with a double click it does not work. Also no error is given.
@FXML
protected void onHelloButtonClick() {
System.out.println("Test");
welcomeText.setText("Welcome to JavaFX Appdssdasdalication!");
try{
Session session = HibernateUtil.getSession();
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Information Dialog");
alert.setHeaderText("Look, an Information Dialog");
alert.setContentText("test");
alert.showAndWait();
session.beginTransaction();
Name name = new Name();
name.setEmail("[email protected]");
name.setEmployeeId(1);
session.save(name);
session.getTransaction().commit();
session.beginTransaction();
String email = session.get(Name.class, 1).getEmail();
welcomeText.setText(email);
alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Information Dialog");
alert.setHeaderText("Look, an Information Dialog");
alert.setContentText(email);
alert.showAndWait();
//welcomeText.setText(((Name)session.createQuery("From Name").list().get(0)).getEmail());
session.getTransaction().commit();
HibernateUtil.shutdown();
}catch(Exception e){
welcomeText.setText(e.toString());
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Information Dialog");
alert.setHeaderText("Look, an Information Dialog");
alert.setContentText(e.toString());
alert.showAndWait();
}
welcomeText.setText("Welcome to sadssaddsadsaasd Appdssdasdalication!");
}
the first test alert is not opened when started via double click.
Java JDK 16.
Thanks for your help!
Solution
I have the answer to my question.
The problem was the hibernate.cfg.xml. I have loaded this file within my program. But when I double clicked my jar the working directory was another one. So he couldnt find the cfg.xml.
Thanks for your help!
Answered By - Guenni97
Answer Checked By - Robin (JavaFixing Admin)