Does anybody know about the hibernate configurations file (hibernate.cfg.xml), what are the "connection" properties - without the "hibernate" prefix - used for?
I mean, why do those properties (such as connection.url, connection.usermame...) exist?
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
...
<property name="connection.url">SOME_URL</property>
<property name="hibernate.connection.url">SOME_URL</property>
<property name="connection.username">SOME_USER</property>
<property name="hibernate.connection.username">SOME_USER</property>
...
Why can I use the both connection.url and hibernate.connection.url ?
ANSWER:
Ok, I believe those properties (without the hibernate. prefix) exist just for backward compatibility with configuration files of older hibernate versions.
Thanks.
The hibernate.connection.url is use to connect the database url following is the configuration setting for hibernate . Hope It will help you.
<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/youdb</property>
<property name="hibernate.connection.username">user</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="emp/dto/Employee.hbm.xml"/>
Related
I am using a 5.4.15.Final version of hibernate. When I am running my application in create mode it is not dropped and create the tables. Is there any way I can do it? I remember I was able to do the same in older version(don't exactly remember the version). My hibernate.cfg.xml file is below:
hibernate.cfg.xml
<?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.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/test</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">5</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.default_schema">test</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.show_sql">true</property>
<property name="output.record.batch.size">10</property>
<property name="javax.persistence.schema-generation.create-source">metadata</property>
<property name="javax.persistence.schema-generation.scripts.action">create</property>
<property name="javax.persistence.schema-generation.database.action">create</property>
<property name="hibernate.hbm2dll.create_namespaces">true</property>
<property name="javax.persistence.schema-generation.scripts.create-target">sql/executors_create.sql</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL81Dialect</property>
</session-factory>
</hibernate-configuration>
I am creating the sessionFactory object as below:
SessionFactory sessionFactory = new Configuration().configure().addAnnotatedClass(Test.class).buildSessionFactory();
Is there any way to solve this?
I am trying following JDBC URL and properties but it's not working with autoReconnect=true.
<properties>
<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/gift20da_jobportal?autoReconnect=true</property>
<property name="hibernate.connection.username">gift20da_jobportal</property>
<property name="hibernate.connection.password">Jobportal#job</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
</properties>
Is there any another way to keep connection?
this got solved my problem.
<!-- Sessions and transactions -->
<!-- Use the C3P0 connection pool provider -->
<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>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="current_session_context_class">thread</property>
add this code in hibernate.cfg.xml , for reference http://liferay-portlets.blogspot.in/2009/01/meanwhile-hibernate-mysql-problems.html .
hibernate.cfg
<session-factory>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.ogm.datastore.provider">MONGODB</property>
<property name="hibernate.ogm.mongodb.database">rcfdb</property>
<property name="hibernate.ogm.mongodb.host">127.0.0.1</property>
<property name="hibernate.ogm.mongodb.port">27017</property>
<property name="hibernate.search.default.directory_provider">filesystem</property>
<property name="hibernate.search.default.indexBase">./Indexes</property>
<property name="hibernate.search.default.locking_strategy">single</property>
<mapping resource="beanDao.hbm.xml"/>
</session-factory>
Getting error with the above hibernate.cfg. Unable to connect to mongoDB.
As pointed out in the comments, you need to set the credentials and the authentication database; these are the properties:
hibernate.ogm.datastore.username
hibernate.ogm.datastore.password
hibernate.ogm.mongodb.authentication_database
You can find the list of properties for MongoDB in the official Hibernate OGM documentation: https://docs.jboss.org/hibernate/stable/ogm/reference/en-US/html_single/#_configuring_mongodb
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.
When using hibernate to retrieve data from Oracle 11g DB using either org.hibernate.dialect.Oracle10gDialect or org.hibernate.dialect.OracleDialect
I get the following:
org.hibernate.exception.SQLGrammarException: could not execute query
Caused by: java.sql.SQLSyntaxErrorException: ORA-00923: FROM keyword not found where expected
Looking in the log we can see the query:
select top ? this_.LI_ILN as LI1_8_0_, this_.COUNTRY_CODE ...
Obviously, the DB doesn't recognize the keyword and this is where the problem lies, because in Oracle pagination can only be done by using ROWNUM, a thing which Hibernate should know.
The hibernate configuration looks as follows:
<hibernate-configuration>
<session-factory name="HibernateSessionFactory">
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.password">...</property>
<property name="hibernate.connection.url">...</property>
<property name="hibernate.connection.username">...</property>
<property name="hibernate.default_schema">...</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.search.autoregister_listeners">false</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">validate</property>
<property name="hibernate.transaction.auto_close_session">false</property>
<mapping resource="HB_Mappings/Supplier.hbm.xml" />
</session-factory>
The query is done like so:
Criteria crit = sessionFactory.getCurrentSession().createCriteria(Supplier.class);
crit.setFirstResult(50 * pageIndex);
crit.setMaxResults(50);
List<Supplier> list = crit.list();
Any help is appreciated.
Solved:
Forgot to mention that I am using spring in which the applicationContext.xml looks like:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:HB_Mappings/hibernate.cfg.xml</value>
</property>
<property name="hibernateProperties">
<value>hibernate.dialect=org.hibernate.dialect.HSQLDialect</value>
</property>
</bean>
It overwrote the hibernate.cfg.xml's property...
Note to self: go easy on copy-paste
OracleDialect is deprecated, see here:
http://docs.jboss.org/hibernate/core/4.1/javadocs/org/hibernate/dialect/OracleDialect.html
Use the Oracle10gDialect instead: http://docs.jboss.org/hibernate/core/4.1/javadocs/org/hibernate/dialect/Oracle10gDialect.html
Also Check this out, and make sure that you are using the newest Oracle JDBC driver.
https://web.archive.org/web/20130204044852/https://community.jboss.org/wiki/SupportedDatabases2