Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Mysql数据库将自定义对象加载到JavaFX Combobox_Java_Hibernate_Javafx_Combobox - Fatal编程技术网

从Mysql数据库将自定义对象加载到JavaFX Combobox

从Mysql数据库将自定义对象加载到JavaFX Combobox,java,hibernate,javafx,combobox,Java,Hibernate,Javafx,Combobox,我正在尝试使用hibernate和dao模式将mysql表中的对象列表加载到javaFX组合框中,下面是我的代码: Main.java public class Main extends Application { @Override public void start(Stage primaryStage) { try { BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("/vie

我正在尝试使用hibernate和dao模式将mysql表中的对象列表加载到javaFX组合框中,下面是我的代码:

Main.java

public class Main extends Application {
@Override
public void start(Stage primaryStage) {
    try {
        BorderPane root = (BorderPane)FXMLLoader.load(getClass().getResource("/view/Home.fxml"));
        Scene scene = new Scene(root,1600,900);
        scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
        primaryStage.setTitle("Dentium");
        primaryStage.setScene(scene);
        primaryStage.setMaximized(true);

        primaryStage.show();

        Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
        primaryStage.setX((primScreenBounds.getWidth() - primaryStage.getWidth()) / 2);
        primaryStage.setY((primScreenBounds.getHeight() - primaryStage.getHeight()) / 4);

    }catch(Exception e) {
        e.printStackTrace();
    }
}

public static void main(String[] args) {
    launch(args);
}
}

其他实施

public class OthersDaoImp implements OthersDao {


@Override
public List<Others> getAllHealthAlerts() {

    List<Others> healthAlerts = new ArrayList<>();
    Transaction transaction = null;
    Session session = HibernateUtil.getSessionFactory().openSession();

    try
    {
        transaction = session.beginTransaction();
        healthAlerts = session.createQuery("from Others").list();
        session.getTransaction().commit();
    }
    catch (RuntimeException e)
    {
        if (transaction != null) {
            transaction.rollback();
        }
        e.printStackTrace();
    }
    finally {
        session.flush();
        session.close();
    }
    return healthAlerts;
}

强制此会话刷新。在提交事务和关闭会话之前,必须在工作单元结束时调用

因此,如果调用
flush()
,在调用
commit()
之前,应该在
try
块中执行此操作

但是,
flush()
所做的是

将基础持久性存储与内存中的持久性状态同步


i、 e.它用当前的内存状态更新数据库。因为在这个事务中没有更改内存中的任何持久对象,所以我认为这个调用是多余的。您应该可以删除此调用。

第60行?'session.flush();'OthersDaoImp.getAllHealthAlerts()的;
INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select others0_.id as id1_0_, others0_.healthAlert as        healthAl2_0_ from others others0_
javafx.fxml.LoadException: 
/D:/Programming/EclipseNeon/DentiumFx/bin/view/Home.fxml

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at application.Main.start(Main.java:16)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.internal.SessionImpl.checkTransactionNeeded(SessionImpl.java:3450)
at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1418)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1414)
at dao.imp.OthersDaoImp.getAllHealthAlerts(OthersDaoImp.java:60)
at controller.PatientController.getHealthAlertsList(PatientController.java:31)
at controller.PatientController.initialize(PatientController.java:115)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 17 more