Advertisement
Guest User

Untitled

a guest
Apr 4th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  5. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">
  6.  
  7. <tx:annotation-driven transaction-manager="transactionManager" />
  8.  
  9. <bean id="transactionManager"
  10. class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  11. <property name="sessionFactory" ref="sessionFactoryBean" />
  12. </bean>
  13.  
  14. <bean id="sessionFactoryBean"
  15. class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  16. <property name="dataSource" ref="dataSource" />
  17. <property name="hibernateProperties">
  18. <props>
  19. <prop key="hibernate.hbm2ddl.auto">create</prop>
  20. <prop key="hibernate.show_sql">true</prop>
  21. <prop key="hibernate.charSet">UTF-8</prop>
  22. </props>
  23. </property>
  24. <property name="packagesToScan">
  25. <list>
  26. <value>az.inventar.model</value>
  27. </list>
  28. </property>
  29.  
  30. <?xml version="1.0" encoding="UTF-8"?>
  31. <beans xmlns="http://www.springframework.org/schema/beans"
  32. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  33. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
  34.  
  35. <bean id="dataSource"
  36. class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  37. <property name="url" value="jdbc:mysql://localhost:3306/inventardb" />
  38. <property name="username" value="root" />
  39. <property name="password" value="123456" />
  40. <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  41. </bean>
  42.  
  43. <?xml version="1.0" encoding="UTF-8"?>
  44. <beans xmlns="http://www.springframework.org/schema/beans"
  45. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  46. xmlns:mvc="http://www.springframework.org/schema/mvc"
  47. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
  48. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
  49. http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
  50.  
  51. <context:annotation-config />
  52. <context:component-scan base-package="az.inventar.*" />
  53. <mvc:annotation-driven />
  54.  
  55. <import resource="spring-database.xml" />
  56. <import resource="spring-hibernate.xml" />
  57.  
  58. <bean
  59. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  60. <property name="prefix" value="/WEB-INF/views/" />
  61. <property name="suffix" value=".jsp" />
  62. </bean>
  63.  
  64. @Entity
  65. @Table(name = "branch")
  66. public class Branch {
  67.  
  68. @Id
  69. @GeneratedValue(strategy = GenerationType.AUTO)
  70. private int id;
  71. private String name;
  72. @OneToOne(fetch = FetchType.LAZY)
  73. @PrimaryKeyJoinColumn
  74. private Employee employee;
  75.  
  76. public Branch() {
  77. super();
  78. // TODO Auto-generated constructor stub
  79. }
  80.  
  81. public Branch(int id, String name, Employee employee) {
  82. super();
  83. this.id = id;
  84. this.name = name;
  85. this.employee = employee;
  86. }
  87.  
  88. public int getId() {
  89. return id;
  90. }
  91.  
  92. public void setId(int id) {
  93. this.id = id;
  94. }
  95.  
  96. public String getName() {
  97. return name;
  98. }
  99.  
  100. public void setName(String name) {
  101. this.name = name;
  102. }
  103.  
  104. public Employee getEmployee() {
  105. return employee;
  106. }
  107.  
  108. public void setEmployee(Employee employee) {
  109. this.employee = employee;
  110. }
  111.  
  112. @Entity
  113. @Table(name = "employee")
  114. public class Employee {
  115.  
  116. @Id
  117. @GeneratedValue(strategy = GenerationType.AUTO)
  118. private int id;
  119. private String name;
  120. private String surname;
  121. @OneToOne
  122. @PrimaryKeyJoinColumn
  123. private Users user;
  124. @OneToOne(fetch = FetchType.LAZY, mappedBy = "branch", cascade = CascadeType.ALL)
  125. private Branch branch;
  126. @OneToMany(fetch = FetchType.LAZY, mappedBy = "equip", cascade = CascadeType.ALL)
  127. private List<Equip> equip;
  128.  
  129. public Employee() {
  130. super();
  131. // TODO Auto-generated constructor stub
  132. }
  133.  
  134. public Employee(int id, String name, String surname, Users user, Branch branch, List<Equip> equip) {
  135. super();
  136. this.id = id;
  137. this.name = name;
  138. this.surname = surname;
  139. this.user = user;
  140. this.branch = branch;
  141. this.equip = equip;
  142. }
  143.  
  144. public int getId() {
  145. return id;
  146. }
  147.  
  148. public void setId(int id) {
  149. this.id = id;
  150. }
  151.  
  152. public String getName() {
  153. return name;
  154. }
  155.  
  156. public void setName(String name) {
  157. this.name = name;
  158. }
  159.  
  160. public String getSurname() {
  161. return surname;
  162. }
  163.  
  164. public void setSurname(String surname) {
  165. this.surname = surname;
  166. }
  167.  
  168. public Users getUser() {
  169. return user;
  170. }
  171.  
  172. public void setUser(Users user) {
  173. this.user = user;
  174. }
  175.  
  176. public Branch getBranch() {
  177. return branch;
  178. }
  179.  
  180. public void setBranch(Branch branch) {
  181. this.branch = branch;
  182. }
  183.  
  184. public List<Equip> getEquip() {
  185. return equip;
  186. }
  187.  
  188. public void setEquip(List<Equip> equip) {
  189. this.equip = equip;
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement