Hibernate Configuration Profile
Hibernate Configuration Profile
Version
Specifies the targetted version of Hibernate you are developping against.
Descriptor
-
Hibernate
-
XML file path: Path to the XML Hibernate Configuration file
(i.e., hibernate.cfg.xml) that specificies the configuration parameters
necessary to create a Hibernate environment. This file isn't required
to be named hibernate.cfg.xml but it must be a valid XML Hibernate Configuration file.
-
Properties file path: Path to the Properties Hibernate Configuration
file (i.e., hibernate.properties). This file is optional and usually defines
configuration parameters not allowed in the XML file. Isn't required to be named
hibernate.properties.
XML Configuration Example
<?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="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://host/db</property>
<property name="connection.username">myUser</property>
<property name="connection.password">myPassword</property>
<mapping resource="com/hibero/demo/City.hbm.xml"/>
<mapping resource="com/hibero/demo/Country.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Note
Hibernate Core and JDBC driver libraries must be included in your project classpath.
-
Spring
-
XML file path: Path to the Spring XML configuration file
(i.e., beans.xml) that specificies the configuration parameters
necessary to create a Hibernate environment.
Beans Example
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="myDataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://host/db_name"/>
<property name="username" value="username"/>
<property name="password" value="password"/>
</bean>
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" value="myDataSource"/>
<property name="mappingResources">
<list>
<value>com/hibero/demo/City.hbm.xml</value>
</list>
</property>
</bean>
</beans>
Note
Hibernate Core, JDBC driver and Spring libraries must be included in your project classpath.
-
Java Persistence API
-
Persistence Unit: Select the Persistence Unit to be used to create
the Hibernate runtime environment from the list of avaliable Persistence Units
in your project.
persistence.xml Example
<?xml version='1.0' encoding='utf-8'?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="myPU">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.hibero.demo.City</class>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.connection.driver_class"
value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url"
value="jdbc:mysql://host/db"/>
<property name="hibernate.connection.username"
value="myUser"/>
<property name="hibernate.connection.password"
value="myPassword"/>
</properties>
</persistence-unit>
</persistence>
Note
Hibernate Core, Annotations, Entity Manager and JDBC driver libraries must be included
in your project classpath.