<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/shop</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping class="hibernate_project.cust" file="cust"
package="hibernate_project" resource="hibernate_project/cust.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I'm making a new project with Hibernate.
I have some problems configure hibernate correctly in my Eclipse environment.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.password">XXXXX</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost/Framework</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.default_schema">Framework</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
My Eclipse environment only sees the master database instead of my Framework database. Can someone help me with this?
The database was not correctly configured. The user didn't have the correct permissions. After fixing this it works.
Here is my code in file named hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.url">jdbc:mysql://localhost:3306/HeartJar</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping resource="com/heartjar/bean/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
There was a waining saying Stream not availableat line 2
Although warnings don't have bad influences to my project.But Understanding how to solve the problem is useful for me,a beginner in JavaWeb.Thank you for your answer
please help me in resolving this error.
org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1494)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.jbpm.db.hibernate.HibernateHelper.createConfiguration (HibernateHelper.java:89)
at org.jbpm.persistence.db.DbPersistenceServiceFactory.getConfiguration (DbPersistenceServiceFactory.java:75)
at org.jbpm.persistence.db.DbPersistenceServiceFactory.getSessionFactory(DbPersistenceServiceFactory.java:104)
at org.jbpm.persistence.db.DbPersistenceService.getSessionFactory(DbPersistenceService.java:93)
at org.jbpm.persistence.jta.JtaDbPersistenceService.getTransactionManager(JtaDbPersistenceService.java:100)
at org.jbpm.persistence.jta.JtaDbPersistenceService.getTransactionStatus(JtaDbPersistenceService.java:88)
at org.jbpm.persistence.jta.JtaDbPersistenceService.<init>(JtaDbPersistenceService.java:50)
at org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory.openService(JtaDbPersistenceServiceFactory.java:61)
at org.jbpm.svc.Services.getService(Services.java:160)
at org.jbpm.svc.Services.getPersistenceService(Services.java:197)
at org.jbpm.JbpmContext.getPersistenceService(JbpmContext.java:695)
at org.jbpm.JbpmContext.getJobSession(JbpmContext.java:639)
at org.jbpm.job.executor.LockMonitorThread.unlockOverdueJobs(LockMonitorThread.java:64)
at org.jbpm.job.executor.LockMonitorThread.run(LockMonitorThread.java:43)
Caused by: org.dom4j.DocumentException: Connection reset Nested exception: Connection reset
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1484)
... 15 more
I am new to hibernate and having difficulty in understanding what the error is. The jar files used for hibernate are as
hibernate-annotations.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate3.jar
my hibernate.cfg.xml file is as
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/datacenter</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<!-- <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
-->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="show_MySql">TRUE</property>
<property name="format_sql">TRUE</property>
<!-- <property name="jboss.as.jpa.providerModule">hibernate3- bundled</property> -->
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<!-- <property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTransla torFactory</property> -->
<!-- List of annotated classes-->
<!-- Associations -->
<!-- One to one -->
<!-- <mapping class="Emp_Timecard" />
<mapping class="maindoor" /> -->
<mapping class="model.serverroom" />
<mapping class="model.resourcelist" />
<mapping class="model.timesheet" />
<mapping class="model.maindoor" />
<!-- <mapping class="timesheet" />
<mapping class="Resource_list"/> -->
</session-factory>
</hibernate-configuration>
I think you are having an issue with connecting to the db properly. Are you sure the user name and password are correct? Or did you have an already a database called datacenter?
Also try changing the doctype as
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
See Can't parse hibernate.cfg.xml while offline
Depending on your hibernate version it might be that hibernate is trying to load the DTD from the internet and that the connection is reset in the meantime.
to run hibernate application offline use 'hibernate-core jar' file it will work..
no need to change your Hibernate configuration file .Avvappa,BEL.
change ur hiber configuration i.e
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
----------------------------to as below -------------------------------------
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.5//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
change your Hibernate configuration as follows;
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
----------------------------to as below -------------------------------------
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.5//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
Try Running the program while your system is connected to Internet
I was facing the same issue. And when i searched for the solution online found this thread regarding the same issue.
I went back and tried running the program again and it worked, the only changes made were connected to Internet Connection. I turned off the connection and again the program was giving the same error as you got.
My guess is the Hibernate configuration file is downloading the DTD from internet, and when it fails to do so it gives error while creating the SessionFactory object.
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
If the configuration file is not parsed, just check for the hibernate version. If it is hibernate 3 the DTD should be from Sourceforge website. if it is the later version the DTD should be
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
Im working in a maven project. Atm I only have entities , mappings and a configuration files. Im trying to test my hibernate mappings with junit.
I cant find the problem. I can validate the xml files in netbeans, but when i run my test I get the following error.
Validation in netbeans:
XML validation started.
Checking file:/C:/Users/Err/Documents/NetBeansProjects/PinkSocks/src/main/resources/hibernate.cfg.xml...
Referenced entity at "http://localhost:8080/files/hibernate-configuration-4.0.xsd".
XML validation finished.
Error:
Initial SessionFactory creation failed.org.hibernate.MappingException: invalid configuration
at bleh.mihihi.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:25)
at bleh.mihihi.utils.HibernateUtil.<clinit>(HibernateUtil.java:16)
at bleh.mihihi.utils.HibernateUtilTest.setUp(HibernateUtilTest.java:20)
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2014)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1931)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1910)
at bleh.mihihi.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:21)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 25; Document is invalid: no grammar found.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration http://localhost:8080/files/hibernate-configuration-4.0.xsd">
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/pinksocks</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<property name="show_sql">true</property>
<mapping class="bleh.mihihi.Beverage" file="Beverage.hbm.xml" />
</session-factory>
</hibernate-configuration>
Beverage.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping
xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping http://localhost:8080/files/hibernate-mapping-4.0.xsd"
package="bleh.mihihi.entities">
<class name="Beverage" table="beverages">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" column="name" />
<property name="alcohol" column="alcohol"/>
</class>
</hibernate-mapping>
Thanks in advance
Err
Edit1:
Things I tried:
retyping
using dtd
placing xsd to other places
With Hibernate 4.x you should use the same DTD as 3.x:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
as you can see by this bug report, where the deprecation warning was removed.
Also the tutorials for 4.2 version use this, as you can see here.
You forgot to specify DTD.
Try keeping below code in both the xml files and let me know
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
your forgot DTD in hibernate.cfg.xml file