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 --^
Related
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
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
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>
I am writing service in hibernate with c3p0 concept.And this service deployed to Raspberry pi.The raspbery pi having 512 mb RAM.I am hit the service continuously, when the processlist goes above 100 connections the mysql hanging up.And my service are not working. After restarting mysql only all processlist killed them self.Then services are working properly till the processlist reach above 100 connections.
My c3p0 configurations are(hibernate.cfg file),
<?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.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">mani</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<property name="current_session_context_class">thread</property>
<!-- <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property> -->
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">10</property>
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.maxIdleTime">1800</property>
<property name="hibernate.c3p0.maxIdleTimeExcessConnections">300</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">30</property>
<property name="hibernate.c3p0.validate">true</property>
<property name="hibernate.c3p0.preferredTestQuery">SELECT 1</property>
<property name="hibernate.c3p0.testConnectionOnCheckin">true</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">false</property>
<!-- Mention here all the pojo classes along with their package name -->
<mapping class="com.nutans.objects.Dialog" />
<mapping class="com.nutans.objects.Office" />
<mapping class="com.nutans.objects.Welcome" />
<mapping class="com.nutans.objects.Sports"/>
</session-factory>
</hibernate-configuration>
Help me out!
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>