Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!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="dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="connection.url">jdbc:mysql://localhost:3306/hibernate_xml</property>
- <property name="connection.username">root</property>
- <property name="connection.password">root</property>
- <property name="show_sql">true</property>
- <property name="hbm2ddl.auto">create</property>
- <property name="format_sql">true</property>
- <!-- mapping configurations -->
- <mapping resource="resources/Employee.hbm.xml" />
- <mapping resource="resources/Department.hbm.xml" />
- </session-factory>
- </hibernate-configuration>
- <?xml version="1.0"?>
- <!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
- <hibernate-mapping>
- <class name="com.domain.Employee" table="employee">
- <id name="id" type="long" column="id">
- <generator class="increment" />
- </id>
- <property name="firstName" name="firstName" />
- <property name="salary" name="salary" />
- <many-to-one name="department" class="com.domain.Department">
- <column name="department" />
- </many-to-one>
- </class>
- </hibernate-mapping>
- <!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
- <hibernate-mapping>
- <class name="com.domain.Department" table="department">
- <id name="id" type="long" column="id">
- <generator class="auto" />
- </id>
- <property name="deptName" column="deptName" />
- </class>
- </hibernate-mapping>
- public static SessionFactory getSessionFactory() {
- SessionFactory sessionFactory = null;
- try {
- sessionFactory = new Configuration().configure("resources/configuration.cfg.xml")
- .addResource("resources/Employee.hbm.xml").addResource("resources/Department.hbm.xml")
- .buildSessionFactory();
- } catch (Throwable ex) {
- throw new ExceptionInInitializerError(ex);
- }
- return sessionFactory;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement