Hibernate configuration on runtime

后端 未结 3 1091
夕颜
夕颜 2020-12-08 11:46

I have hibernate.cfg.xml file.



    
    

        
3条回答
  •  渐次进展
    2020-12-08 12:38

    Try like this it is working fine

    AnnotationConfiguration conf = new AnnotationConfiguration().configure("/dronehibernate.cfg.xml");
    
    conf.setProperty("hibernate.connection.url","jdbc:mysql://localhost/PAT_DRONE_DB1");
    
    SessionFactory sessionFactory = conf.buildSessionFactory();
    
    Session session = sessionFactory.openSession();
    
    List channelList = session.createQuery("from NetworkType").list();
    

提交回复
热议问题