Failed to create sessionFactory object.org.hibernate.HibernateException

后端 未结 3 1818
粉色の甜心
粉色の甜心 2021-01-16 11:55

Hi I am new to the hibernate framework.when i am running hibernate sample example code it is working fine if internet connection is available.If internet connection is not a

相关标签:
3条回答
  • 2021-01-16 12:19

    There may be the case that your ManageEmployee.java is not able to populate the configuration(hibernate.cfg.xml) file.You can add the below piece of code to populate the configuration file.

    Configuration cfg=new Configuration();  //create Configuration object first
    
    cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file  
    factory=cfg.buildSessionFactory(); //then u can create session factory object and u can begin your transaction
    

    The following worked for me hope it work for you also :)

    0 讨论(0)
  • 2021-01-16 12:25

    I see one similar question today and I answered. Seems like your hbm file also has DOCTYPE mismatch. Check it once. It should work.

    Failed to create sessionFactory object.org.hibernate.InvalidMappingException: Could not parse mapping document from resource Employee.hbm.xml

    Use below doctype:

    0 讨论(0)
  • 2021-01-16 12:41

    See the 3rd & 4th lines in your hibernate configuration & mapping file respectively.

    The document for DTD says:

    Hibernate will not load the DTD file from the web, but first look it up from the classpath of the application. The DTD file is included in hibernate-core.jar (it is also included in the hibernate3.jar, if using the distribution bundle).

    You're getting this exception in absence of Internet because MOSTLY it tries to load DTD files for both hibernate configuration & mapping files, from Internet, in your application.

    When your application is started & the first time it accesses hibernate configuration file it tries to parse the configuration file using its DTD file, which is downloaded from www.hibernate.org.

    For more on Hiberate DTD, please have a look at these:

    http://forum.spring.io/forum/spring-projects/data/73208-how-to-configure-hibernate-cfg-xml-to-work-offline

    http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/tutorial.html#tutorial-firstapp-mapping

    UPDATE :-

    How to work with Hibernate Offline?

    For Hibernate Configuration file:

    1. Change your DTD file declaration to

      <!DOCTYPE hibernate-configuration SYSTEM "hibernate-configuration-3.0.dtd">

    2. Download hibernate configuration DTD file from : http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd & set it to your classpath.

    For hibernate mapping files:

    1. Change your DTD file declaration to

      <!DOCTYPE hibernate-configuration SYSTEM "hibernate-mapping-3.0.dtd">

    2. Download hibernate configuration DTD file from : http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd & set it to your classpath.

    This should work properly.

    0 讨论(0)
提交回复
热议问题