Hibernate configuration on runtime

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

I have hibernate.cfg.xml file.



    
    

        
相关标签:
3条回答
  • 2020-12-08 12:22

    Use constants from Environment class

    0 讨论(0)
  • 2020-12-08 12:28

    Try to call conf.configure(); here.
    And properties may need to have hibernate prefix like "hibernate.connection.username"
    Hope it helps.

    0 讨论(0)
  • 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<NetworkType> channelList = session.createQuery("from NetworkType").list();
    
    0 讨论(0)
提交回复
热议问题