Error creating Hibernate Mapping Files and PJOS from Database - java

I use java version 8.0.2 and Mysql Gui 9:02 software.I try to create Hibernate Mapping Files and PJOS from Database but I always get the following error message
Hibernate configuration fails with message:Could not get list of suggested identity strategies from database. Probably a JDBC driver problem. see message.log for exception details.
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/mind_1.0.2?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>
Please Help Me!

I think you missed the db password tag.
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/DBname
</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect
</property>
<property name="show_sql">false</property>
<property name="hbm2ddl.auto">update</property>

Maybe your database name is not right.
And try to add
<property name="hibernate.default_schema">dbo</property>

Related

I have an error in my hibernate.cfg.xml file

This is the cfg file:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/employee
</property>
<property name="hibernate.connection.username">root</property>
<property
name="hibernate.connection.password">Chitaramea2198</property>
<property name="hibernate.connection.pool_size">50</property>
<property name="show_sql">true</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping resource="src/Main/Employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The error:
Exception in thread "main" org.hibernate.MappingNotFoundException:
resource: src/Main/Employee.hbm.xml not found
My project structure:
Does anybody know how could I fix this error? I tried different
paths for the hbm xml file , i even tried to move it same place
with the cfg file but it still doesnt work, I am a newbie and dont
really know much about it, I tried to follow some tutorials but I
still cannot manage to make it work.
Thank you!
This is the project:
https://wetransfer.com/downloads/8d00be7b4a302b7cca39c87a6bc42f4a20200125220719/309934c0d43ae5bb15201ba3850ba14b20200125220719/01da4d

No Suitable driver found for jdbc:microsoft:sqlserver... while connecting sqlserver with hibernate

Configuration file
<?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">
com.microsoft.sqlserver.jdbc.SQLServerDriver
</property>
<property name="hibernate.connection.url">
jdbc:microsoft:sqlserver://171.1.8.4;databaseName:master
</property>
<property name="hibernate.connection.username">
usename
</property>
<property name="hibernate.connection.password">
password
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="hibernate.default_schema">
dbo
</property>
<property name="show_sql">true</property>
<mapping resource="practice041116/Cls.hbm.xml" />
</session-factory>
</hibernate-configuration>
Here is the stack trace
How to resolve it as i have went through few answers like this but its not helping Thanks in advance
The rest of the code is available here

mysql utf-8 returns gibberish from one machine

I have mysql DB with UTF-8 and application written in java with hibernate. When I run the application in eclipse everything is fine. But in production which is on a different machine the values returned from DB are corrupted.
I print the values to log (immediately after getting them) and I clearly see that the values I get from DB are corrupted in production.
The DB itself is the same DB for both environments. The values are stored fine.
Any ideas what can be the reason for this?
UPDATE:
I forgot to say that it happens sometimes. I think that in 50% of the times it works fine.
UPDATE 2:
Here is the hibernate.cfg.xml:
<!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.url">jdbc:mysql://myDB:3306/myApp?autoReconnect=true&useUnicode=true&createDatabaseIfNotExist=true&characterEncoding=utf-8</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>
<!-- <property name="hibernate.connection.pool_size">10</property> -->
<property name="hibernate.connection.isolation">2</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.connection.provider_class">com.zaxxer.hikari.hibernate.HikariConnectionProvider</property>
<property name="hibernate.hikari.minimumIdle">5</property>
<property name="hibernate.hikari.maximumPoolSize">10</property>
<property name="hibernate.hikari.idleTimeout">30000</property>
<mapping class="someclass1"/>
<mapping class="someclass2"/>
<mapping class="someclass3"/>
<mapping class="someclass4"/>
</session-factory>
</hibernate-configuration>
Reference URL: https://docs.jboss.org/exojcr/1.12.13-GA/developer/en-US/html/ch-db-configuration-hibernate.html
Please verify the datasource configuration in your production environment whether the attributes - useUniCode and characterEncoding are set properly. Example:
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/exodb?relaxAutoCommit=true&amp;autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf8"/>

XML Parsing Error - Hibernate

I am trying to run my first Hibernate Program.
I can't figure out the problem, because the matching end-tag is actually there?
Thanks for your help in advance!
Error parsing XML: /hibernate.cfg.xml(11) The element type "session-factory" must be terminated by the matching end-tag
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>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class" /> com.mysql.jdbc.Driver </property>
<property name="hibernate.connection.url"/>jdbc:mysql://localhost:3306/westbahn</property>
<property name="hibernate.connection.username" />root</property>
<property name="hibernate.connection.password" />secretpassword</property>
<property name="hibernate.dialect" />org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect"> org.hibernate.dialect.MySQLInnoDBDialect" </property>
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.hbm2ddl.auto">create</property>
</session-factory>
</hibernate-configuration>
Hibernate configuration file should look like this
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:#localhost:1521:xe</property>
<property name="connection.user">xxx</property>
<property name="connection.password">xxxx</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping resource="xxxx.hbm.xml"/>
</session-factory>
</hibernate-configuration>
This could help you out!!
Your 5 first property elements are wrong: you use self-closing elements although they have a body. For example:
<property name="hibernate.connection.driver_class" /> com.mysql.jdbc.Driver </property>
should be
<property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver </property>
no slash here --^

org.hibernate.TransactionException: JDBC rollback failed exception

I'm using Tomcat server, I started it yesterday morning and it continuously runs until this morning, but when I tried to login in my application it shows:
org.hibernate.TransactionException: JDBC rollback failed
What is the problem - is any persistent session here or is sessionfactory null?
I got the problem ,
ie i attached a different jar named c3p0-0.9.1.jar file and add some lines in hibernate-cfg.xml file
The code is :
<?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.MySQL5InnoDBDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/<your db name></property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">test</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.jdbc.batch_size">50</property>
//Here is the extra code for handling the above problem.....
**<property name="hibernate.c3p0.max_size">1</property>
<property name="hibernate.c3p0.min_size">0</property>
<property name="hibernate.c3p0.timeout">5000</property>
<property name="hibernate.c3p0.max_statements">1000</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.acquire_increment">1</property>**
</session-factory>
</hibernate-configuration>

Categories