I'm trying to set up Hibernate, and since 4.0.0 just came out I naturally decided to go with that. It seems that no matter what way I try to create a SessionFactory, it always leads to the same error:
Initial SessionFactory creation failed.java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.envers.event.EnversIntegrator could not be instantiated: java.lang.ClassCastException: Cannot cast org.hibernate.envers.event.EnversIntegrator to org.hibernate.integrator.spi.Integrator
It seems like there is something wrong with my Hibernate configuration but I can't figure out what. Here's my 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.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://192.168.0.17:5432/mydb</property>
<property name="connection.username">myusrname</property>
<property name="connection.password">mypasswd</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- c3p0 configuration -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
</session-factory>
</hibernate-configuration>
Does anyone spot anything out of the ordinary, or do you have other ideas?
I found no way to get Hibernate 4.0.0 CR4 working. Switching to 3.6.7 resolved the problem and works just fine. I conclude that there must be some bug in the release, and will file a bug report.
Related
Whenever I run my server my database table are re-created and all my previous data are being deleted. I was thinking this might be the problem in hibernate configuration file but don't know the actual reason hope you awesome guys will figure me out .
I also tried changing <property name="hibernate.hbm2ddl.auto">update</property> to auto , validate but didnot help
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"http://www.hibernate.org/dtd/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.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<!-- Assume test is the database name -->
<property name="hibernate.connection.url">
jdbc:mysql://localhost:3306/restro
</property>
<property name="hibernate.connection.username">
root
</property>
<property name="hibernate.connection.password">
root
</property>
<!-- <property name="connection.release_mode">auto</property> -->
<!-- Drop and re-create the database schema on startup -->
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Names the annotated entity class -->
<mapping class="com.restroo.model.MenuItems"/>
<mapping class="com.restroo.model.AdminUser"/>
</session-factory>
</hibernate-configuration>
This is my configuration:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-5.0.dtd">
<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">
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping resource="org/hibernate/tutorial/domain/Event.hbm.xml"/>
<mapping class="Mapping.AccountMap"
</session-factory>
</hibernate-configuration>
I read that i should change the "Doctype" and i did from other answers i have found, yet this error occurs:
Unable to perform unmarshalling at line number 8 and column 63 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.
Your dtd url is false ... seems like hibernate-configuration-5.0.dtd doesn't exist ... use this :
http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd
change the whole header :
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-5.0.dtd">
<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
<?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>
Try to add this header block. It works for me and also check parse error in your XML 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">
Here i am posting some sample xml file may be it will help you.
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Names the annotated entity class -->
<mapping class="org.java.dto.UserDetails"/>
</session-factory>
</hibernate-configuration>
I'm trying to add c3p0 connection pool to our existing hibernate configuration.
But it has no affect and hibernate still uses default pool.
Hibernate Configuration alone is working fine so i am absolutely sure no problem with it.
Wondering if someone here can point my mistake Or suggest how i can debug the problem ?
I do not use Spring framework.
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="hibernate.connection.password">passwd</property>
<property name="hibernate.connection.url">jdbc:db2://server:port/database</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.default_schema">DB Schema</property>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.format_sql">false</property>
<property name="hibernate.max_fetch_depth">4</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.connection.isolation">1</property>
<property name="hibernate.jdbc.batch_size">50</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">3000</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">900</property>
<mapping resource="table.hbm.xml" />
</session-factory>
</hibernate-configuration>
Here are the jars i have:
hibernate3.jar
hibernate-c3p0-3.5.0-Final.jar
Statements from the logs:
hibernate.cfg.Environment - Hibernate 3.5.0-Final
INFO ManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
INFO ManagerConnectionProvider - Hibernate connection pool size: 20
Try configuring a connection provider class from c3p0.
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
Also, it's better to add the hibernate configuration doctype, which will help in finding any typos.
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
UPDATE
You need to include the mchange library in your classpath. This link might helpful to you.
Hi i created a Hibernate powered hsql embedded swing app..When i run eclipse juno version it run perfectly..After that i export as runnable jar file as run it.But does not retrieve,add data database...!!!
Project directory like
Project
..src
.....dao
.....daoimpl
.....sevice
.....serviceimpl
.....domain
.....main
.....hibernate.cfg.xml
..db/hsql/library
.............library.script
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>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Database connection settings -->
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.url">jdbc:hsqldb:db/hsql/library;shutdown=true</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">sa</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- JDBC connection pool (use the built-in one) -->
<property name="connection.pool_size">1</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property
name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- disable batching so HSQLDB will propagate errors correctly. -->
<property name="jdbc.batch_size">0</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- List all the mapping documents we're using -->
<mapping class="com.habitz.librarymanagement.domain.Admin" />
<mapping class="com.habitz.librarymanagement.domain.Book" />
<mapping class="com.habitz.librarymanagement.domain.Category" />
<mapping class="com.habitz.librarymanagement.domain.Group" />
<mapping class="com.habitz.librarymanagement.domain.Issue" />
<mapping class="com.habitz.librarymanagement.domain.Member" />
</session-factory>
</hibernate-configuration>
Someone know please help...!!
This property creates a database relative to where the jar was executed from.
<property name="hibernate.connection.url">jdbc:hsqldb:db/hsql/library;shutdown=true</property>
Relative URL's do not work. Use an absolute URL. For example, you can use the user's directory for the database files, or a directory that your app is installed in.
I am new to Hibernate .... i tried this code but i got Could not parse configuration: NewFile.cfg.xml (name of .cfg.xml 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>
<!-- connection to oracle -->
<propertyname="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver </property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#localhost:1521:XE
</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.connection.username">system</property>
<property name="hibernate.connection.password">system</property>
<!-- autocommit -->
<property name="hibernate.connection.autocommit">false</property>
<!-- to display sql query generated while running program -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="use_sql_comments">true</property>
<!-- for jdbc transaction -->
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.
JDBCTransactionFactory</property>
<!-- mapping file -->
<mapping resource="Mapping.hbm.xml"/>
</session-factory>
The end tag for <hibernate-configuration> is missing:
</hibernate-configuration>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver </property>
Your opening tag not match the ending tag.