Hibernate Exception while deploying on VPS server - java

I am using VPS server first time to deploy my application. I have created a Hibernate Project. After Deploying it is giving me following error
org.hibernate.HibernateException: Could not parse configuration:
/hibernate.cfg.xml
org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246)
org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:230)
org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:71)
org.hibernate.cfg.Configuration.configure(Configuration.java:2158)
org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:212)
org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:71)
org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:206)
util.HibernateUtil.(HibernateUtil.java:26)
services.HibernateServices.(HibernateServices.java:41)
servlet.GetShopProfile.processRequest(GetShopProfile.java:42)
servlet.GetShopProfile.doGet(GetShopProfile.java:77)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
To test if my database is working fine, I created a normal database connection class and it was working fine.
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.pool_size">1</property>
<property name="hibernate.current_session_context_class">thread</property>
<!--<property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property>-->
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<mapping class="pojo.TestClass"/>
</session-factory>
</hibernate-configuration>
Directory Structure
WEB-INF
classes
pojo
TestClass.class
services
HibernateService.class
servlet
TestServlet.class
util
HibernateUtil.class
hibernate.cfg.xml
We have Tomcat 7.0 installed.
Kindly help!!!

I solved the problem by reinstalling the tomcat on my server.
Any ways this issue can be solved by changing the DTD as suggested in questions: here
I tried multiple solutions in my case but at last when nothing worked I reinstalled the tomcat and every thing was fine
Thanks every one for their inputs and time.

Can you try adding space in your commented lines?
<!--<property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property>-->
Replace above line with
<!-- <property name="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</property> -->
I think starting tag < after your comment start section is causing xml parsing issue.

Change the hibernate.cfg.xml as
<?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">

Related

Exception when running JavaFX app using Hibernate on Android

I have a JavaFX desktop application. It accesses a remote MySQL database via Hibernate and LAN/WiFi.
I now try to port it with an as small as possible effort to Android 8.1 using Gluon mobile/javafxports.
When running the app on Android I get the following exception:
Could not parse configuration: commonhibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2105)
EDIT: Content of commonhibernate.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>
<mapping resource="Gender.hbm.xml"/>
<mapping resource="Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
On the (Windows-)PC the application runs well without this exception.
From other posts here on stackoverflow I understand that there is doubt that Hibernate can/should be used on Android.
But since these posts are 5 years old or older, I like to ask whether this is still the case and if someone can help regarding abbove exception on Android ?
Looks like you are missing the connection parameters.
Here example of configuration:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM "classpath://org/hibernate/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">URL_CONNECTION</property>
<property name="connection.username">YOUR_USERNAME</property>
<property name="connection.password">YOUR_PASSWORD</property>
<mapping resource="Gender.hbm.xml"/>
<mapping resource="Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Cannot resolve class dialect

I am trying to fix an issue for hours but nothing seems to work.I tried everything available online. I am using Intellij IDEA. I am using a Maven project. I have created hibernate.cfg.xml with following content
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</property>
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping class="User"/>
</session-factory>
</hibernate-configuration>
Following line is throwing an error that cannot resolve class dialect
<property name="dialect">org.hibernate.dialect.H2Dialect</property>
My External Libraries structure looks like this.
any help would be appreciated.
I fixed the problem. The problem was Intellij IDEA was not able to download maven files for Hibernate. I used maven repository for adding the repository.

Java Hibernate invalid mapping exception

My code was working just fine with the xml mapping then I changed to annotations and i get this error:
Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
This is my 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>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/hibernate1?useLegacyDatetimeCode=false&serverTimezone=UTC</property>
<property name="connection.username">hibernate1</property>
<property name="connection.password">mypassword</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.show_sql">true</property>
<mapping class="hibernate.Profesor" file="" jar="" package="" resource=""/>
<mapping class="hibernate.Direccion" file="" jar="" package="" resource=""/>
</session-factory>
</hibernate-configuration>
I was able to get it to work for me changing only connection.url, connection.username, and connection.password with:
// A SessionFactory is set up once for an application
SessionFactory sessionFactory = new Configuration()
.configure() // configures settings from hibernate.cfg.xml
.buildSessionFactory();
Delete your mapping configuration files. That is, delete Profesor.hbm.xml and Direccion.hbm.xml if they still exist. You don't need them if you are using annotations.
If you are using Maven, make sure you have the following dependencies:
mysql-connector-java
hibernate-core
Also, com.mysql.jdbc.Driver is deprecated. Use com.mysql.cj.jdbc.Driver.
It would be more helpful if you posted the exception's entire stack trace.

Error: Could not find or load main class org.hibernate.dialect.DB2390Dialect

When I run my program I get this error:
Error: Could not find or load main class
org.hibernate.dialect.DB2390Dialect
I have checked all the jar files required are in place. Please help. I guess there is problem with the hibernate configuration file. Find the configuration file below:
<?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>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">batch</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#localhost:1521:xe</property>
<property name="hibernate.connection.username">batch</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">none</property>
<mapping resource="galaxe.model.Network" />
</session-factory>
</hibernate-configuration>
In configuration you need to mention for DB2390 as below
property name="hibernate.dialect" value="org.hibernate.dialect.DB2390Dialect"
if you use oracle, it will be different
property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect">

Netbeans 7.1 Hibernate Reverse Engineering wizard does not find database driver

I am currently trying to get through this netbeans + hibernate + JavaSE tutorial ( http://netbeans.org/kb/docs/java/hibernate-java-se.html). All is pretty fine, but after the creation of the hibernate.cfg.xml when it comes to the part where reverse engineering should be applied it comes to some weird message that the reverse-engineering wizard tells me:
"The database drivers are not added to the project classpath."
"Go to project properties to add database library.".
Well that's kind of weird, because the hibernate.cfg.xml was generated by netbeans. I've checked my database connection with the connection data from the hibernate.cfg.xml and it seems to be all okay, so connecting manually works pretty fine. Anyone knows what is going on here? Am I doing something wrong?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sakila</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">apassword</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
</session-factory>
</hibernate-configuration>
Add these line of code in hibernate.cfg.xml
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/DATABASE_NAME</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"/>
</session-factory>
Besides missing jar files, here is another possible way that could cause this error in netbeans: wrong configuration file.
So make sure you have the correct configuration file (.cfg.xml file) to build .reveng
Attached an example configuration:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">1234</property>
<property name="hibernate.connection.url">jdbc:mysql://161.58.103.144:3306/exampleDatabase?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">JasonGlez</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
Just change the ip, the name of the database, your username and password
You are missing the JDBC Driver. At the Project View right click the Libraries node under your project and choose Add Library... -> MySQL JDBC Driver.
As mentioned by hello, make sure the hibernate.cfg.xml is good. Try regenerating it though from Netbeans Hibernate Configuration Wizard as opposed to crafting it yourself. Also try recreating the project and make sure the new project wizard populates the hibernate.cfg.xml with database connection settings. It came out blank for me the first time; not sure why. Before it started working, I had also restarted Netbeans and the computer to boot, which might not hurt to try. (No pun intended.)
This required MySQL driver, Add My sql Driver in Library to resolve the issue

Categories