Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not parse configuration: hibernate-annotation.cfg.xml


This is the error I am getting. Application runs properly all the time except for 2 incidents when application was throwing this error.

My primary guess is some how java/hibernate was failing to connect with mysql server. Which I am also investigating. But Not exactly sure what is happening. Here is configuration file for curious mind
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
		"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
		"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<session-factory>
		<!-- Database connection properties - Driver, URL, user, password -->
		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="hibernate.connection.url">${mysql_url}</property>
		<property name="hibernate.connection.username">${mysql_user}</property>
		<property name="hibernate.connection.password">${mysql_pass}</property>

		<!-- org.hibernate.HibernateException: No CurrentSessionContext configured! -->
		<property name="hibernate.current_session_context_class">thread</property>
		<!-- <property name="hibernate.show_sql">true</property> -->
		<!-- <property name="hibernate.format_sql">true</property> -->
		<property name="connection.autocommit">true</property>

		<!-- Mapping with model class containing annotations -->
		<mapping class="*.hibernatemodel.*" />
	</session-factory>
</hibernate-configuration>


What I have tried:

I went through logs, it offers nothing much. If it was a consistent error, I would have known, I guess. Expecting to hear peoples experience. If you need any further information, please let me know.


--further findings--
hibernate access the url http://hibernate.org/dtd/hibernate-configuration-3.0.dtd in runtime. If for whatever the reason application fail to connect with internet my application will fail. If I remove the Doctype all together, application fails. And I do not like my batch accessing every minute(my batch runs every minute).

Does anyone know any potential solution? Besides getting rid off Hibernate of course.
Posted
Updated 31-Jul-18 21:16pm
v3

1 solution

After searching on google on the right topic, I found the solution in for DTD file. Using local file will solve the problem.

And hibernate-core has a dtd file. So the solution is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
		"classpath://org/hibernate/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<session-factory>
		<!-- Database connection properties - Driver, URL, user, password -->
		<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="hibernate.connection.url">${mysql_url}</property>
		<property name="hibernate.connection.username">${mysql_user}</property>
		<property name="hibernate.connection.password">${mysql_pass}</property>
		<property name="hibernate.current_session_context_class">thread</property>
		<property name="connection.autocommit">true</property>

		<!-- Mapping with model class containing annotations -->
		<mapping class="*.hibernatemodel.*" />
	</session-factory>
</hibernate-configuration>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900