Thursday, October 27, 2011

Hibernate Configuration

Currently, I would prefer separating hibernate configuration into 2 files. With this, we can use spring to integrate and reuse the properties stated with EL. Hibernate will load the properties into config automatically as long as u name the file and variable correctly. Next post, I will show how to use EL to inject into bean automatically and the optimal setup for xml.

hibernate.cfg.xml
<hibernate-configuration>
<session-factory name="java:hibernate/SessionFactory">
<mapping resource="com/gl/dao/Country.hbm.xml">
</mapping></session-factory>
</hibernate-configuration>

hibernate.properties
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://127.0.0.1:3306/glapp
hibernate.connection.username=root
hibernate.connection.password=password
hibernate.current_session_context_class=thread
hibernate.query.factory_class=org.hibernate.hql.classic.ClassicQueryTranslatorFactory
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=true