Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. <!DOCTYPE hibernate-configuration PUBLIC
  2. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  3. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  4. <hibernate-configuration>
  5. <session-factory>
  6. <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  7. <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  8. <property name="connection.url">jdbc:mysql://localhost:3306/hibernate_xml</property>
  9. <property name="connection.username">root</property>
  10. <property name="connection.password">root</property>
  11. <property name="show_sql">true</property>
  12. <property name="hbm2ddl.auto">create</property>
  13. <property name="format_sql">true</property>
  14.  
  15. <!-- mapping configurations -->
  16.  
  17. <mapping resource="resources/Employee.hbm.xml" />
  18. <mapping resource="resources/Department.hbm.xml" />
  19.  
  20. </session-factory>
  21. </hibernate-configuration>
  22.  
  23. <?xml version="1.0"?>
  24. <!DOCTYPE hibernate-mapping PUBLIC
  25. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  26. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  27. <hibernate-mapping>
  28. <class name="com.domain.Employee" table="employee">
  29. <id name="id" type="long" column="id">
  30. <generator class="increment" />
  31. </id>
  32. <property name="firstName" name="firstName" />
  33. <property name="salary" name="salary" />
  34.  
  35. <many-to-one name="department" class="com.domain.Department">
  36. <column name="department" />
  37. </many-to-one>
  38. </class>
  39. </hibernate-mapping>
  40.  
  41. <!DOCTYPE hibernate-mapping PUBLIC
  42. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  43. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  44. <hibernate-mapping>
  45. <class name="com.domain.Department" table="department">
  46. <id name="id" type="long" column="id">
  47. <generator class="auto" />
  48. </id>
  49. <property name="deptName" column="deptName" />
  50. </class>
  51. </hibernate-mapping>
  52.  
  53. public static SessionFactory getSessionFactory() {
  54. SessionFactory sessionFactory = null;
  55. try {
  56. sessionFactory = new Configuration().configure("resources/configuration.cfg.xml")
  57. .addResource("resources/Employee.hbm.xml").addResource("resources/Department.hbm.xml")
  58. .buildSessionFactory();
  59. } catch (Throwable ex) {
  60. throw new ExceptionInInitializerError(ex);
  61. }
  62. return sessionFactory;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement