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
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 :)
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:
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:
Change your DTD file declaration to
<!DOCTYPE hibernate-configuration SYSTEM "hibernate-configuration-3.0.dtd">
Download hibernate configuration DTD file from : http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd & set it to your classpath.
For hibernate mapping files:
Change your DTD file declaration to
<!DOCTYPE hibernate-configuration SYSTEM "hibernate-mapping-3.0.dtd">
Download hibernate configuration DTD file from : http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd & set it to your classpath.
This should work properly.