Advertisement
Guest User

Untitled

a guest
Sep 7th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/appconfig-data.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
  2.  
  3. @Entity
  4. @Table(name = "users")
  5. public class UserEntity {
  6.  
  7. @Id
  8. @GeneratedValue(strategy = GenerationType.AUTO)
  9. private Long id;
  10.  
  11. @Column(name = "username")
  12. protected String username;
  13.  
  14. @Column(name = "password")
  15. protected String password;
  16.  
  17. @Transient
  18. private String confirmPassword;
  19.  
  20. @ManyToMany
  21. @JoinTable(name = "user_roles", joinColumns = @JoinColumn(name = "user_id"),
  22. inverseJoinColumns = @JoinColumn(name = "role_id"))
  23. private Set<Role> roles;
  24.  
  25. public Long getId() {
  26. return id;
  27. }
  28.  
  29. public void setId(Long id) {
  30. this.id = id;
  31. }
  32.  
  33. public String getUsername() {
  34. return username;
  35. }
  36.  
  37. public void setUsername(String username) {
  38. this.username = username;
  39. }
  40.  
  41. public String getPassword() {
  42. return password;
  43. }
  44.  
  45. public void setPassword(String password) {
  46. this.password = password;
  47. }
  48.  
  49. public String getConfirmPassword() {
  50. return confirmPassword;
  51. }
  52.  
  53. public void setConfirmPassword(String confirmPassword) {
  54. this.confirmPassword = confirmPassword;
  55. }
  56.  
  57. public Set<Role> getRoles() {
  58. return roles;
  59. }
  60.  
  61. public void setRoles(Set<Role> roles) {
  62. this.roles = roles;
  63. }
  64.  
  65. @Entity
  66. @Table(name = "roles")
  67. public class RoleEntity{
  68.  
  69. @Id
  70. @GeneratedValue(strategy = GenerationType.AUTO)
  71. private Long id;
  72.  
  73. @Column(name = "name")
  74. private String name;
  75.  
  76. @ManyToMany(mappedBy = "roles")
  77. private Set<User> users;
  78.  
  79. public RoleEntity() {
  80. }
  81.  
  82. public Long getId() {
  83. return id;
  84. }
  85.  
  86. public void setId(Long id) {
  87. this.id = id;
  88. }
  89.  
  90. public String getName() {
  91. return name;
  92. }
  93.  
  94. public void setName(String name) {
  95. this.name = name;
  96. }
  97.  
  98. public Set<User> getUsers() {
  99. return users;
  100. }
  101.  
  102. public void setUsers(Set<User> users) {
  103. this.users = users;
  104. }
  105.  
  106. @Override
  107. public String toString() {
  108. return "Role{" +
  109. "id=" + id +
  110. ", name='" + name + ''' +
  111. ", users=" + users +
  112. '}';
  113. }
  114.  
  115. public class User extends UserEntity implements Comparable {
  116.  
  117. private boolean isOnline;
  118. private String sex;
  119. private int age;
  120. private String comment;
  121. private String email;
  122. private String friendsLogins;
  123. private Session session;
  124.  
  125. public User(String login, String password) {
  126. this.sex = null;
  127. this.comment = null;
  128. this.email = null;
  129. this.friendsLogins = "";
  130.  
  131. }
  132.  
  133. public User(User user) {
  134. this.sex = user.getSex();
  135. this.comment = user.getComment();
  136. this.email = user.getComment();
  137. this.friendsLogins = "";
  138.  
  139. }
  140.  
  141. public User(String login, String password, boolean isOnline, String sex, int age, String comment, String email) {
  142. this.sex = sex;
  143. this.age = age;
  144. this.comment = comment;
  145. this.email = email;
  146. this.friendsLogins = "";
  147. }
  148.  
  149. public Session getSession() {
  150. return session;
  151. }
  152.  
  153. public void setSession(Session session) {
  154. this.session = session;
  155. }
  156.  
  157.  
  158. public boolean isOnline() {
  159. return isOnline;
  160. }
  161.  
  162. public void setOnline(boolean online) {
  163. isOnline = online;
  164. }
  165.  
  166. public String getSex() {
  167. return sex;
  168. }
  169.  
  170. public void setSex(String sex) {
  171. this.sex = sex;
  172. }
  173.  
  174. public int getAge() {
  175. return age;
  176. }
  177.  
  178. public void setAge(int age) {
  179. this.age = age;
  180. }
  181.  
  182. public String getComment() {
  183. return comment;
  184. }
  185.  
  186. public void setComment(String comment) {
  187. this.comment = comment;
  188. }
  189.  
  190. public String getEmail() {
  191. return email;
  192. }
  193.  
  194. public void setEmail(String email) {
  195. this.email = email;
  196. }
  197.  
  198. public String getFriendsLogins() {
  199. return friendsLogins;
  200. }
  201.  
  202. public void setFriendsLogins(String friendsLogins) {
  203. this.friendsLogins = friendsLogins;
  204. }
  205.  
  206. public boolean equals(Object obj) {
  207. User user = (User) obj;
  208. if (user.getPassword().equals(this.password) && user.getUsername().equals(this.username)) {
  209. return true;
  210. } else {
  211. return false;
  212. }
  213. }
  214.  
  215.  
  216. @Override
  217. public int compareTo(Object o) {
  218. User user = (User) o;
  219. if (user.getPassword().equals(this.password) && user.getUsername().equals(this.username)) {
  220. return 0;
  221. } else if (user.getAge() > this.getAge()) {
  222. return -1;
  223. } else {
  224. return 1;
  225. }
  226. }
  227.  
  228. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  229. <property name="driverClassName" value="${jdbc.driverClassName}"/>
  230. <property name="url" value="${jdbc.url}"/>
  231. <property name="username" value="${jdbc.username}"/>
  232. <property name="password" value="${jdbc.password}"/>
  233. </bean>
  234.  
  235. <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  236. <property name="dataSource" ref="dataSource"/>
  237. <property name="packagesToScan" value="com.chat.my.model"/>
  238. <property name="jpaVendorAdapter">
  239. <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
  240. </property>
  241. <property name="jpaProperties">
  242. <props>
  243. <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
  244. <prop key="hibernate.show_sql">true</prop>
  245. </props>
  246. </property>
  247. </bean>
  248.  
  249. <bean id="transactionManager"
  250. class="org.springframework.orm.jpa.JpaTransactionManager">
  251. <property name="entityManagerFactory" ref="entityManagerFactory"/>
  252. </bean>
  253.  
  254. <tx:annotation-driven/>
  255. <jpa:repositories base-package="com.chat.my.dao"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement