Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. КОНФИГ
  2. <?xml version='1.0' encoding='utf-8'?>
  3. <!DOCTYPE hibernate-configuration PUBLIC
  4. "-//Hibernate/Hibernate Configuration DTD//EN"
  5. "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  6. <hibernate-configuration>
  7. <session-factory>
  8. <property name="connection.url">jdbc:mysql://localhost:3306</property>
  9. <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  10.  
  11. <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  12. <property name="connection.username">root</property>
  13. <property name="connection.password">root</property>
  14. <property name="show_sql">true</property>
  15. <!-- DB schema will be updated if needed -->
  16. <property name="hbm2ddl.auto">update</property>
  17.  
  18. <!--<mapping resource="model/UsersEntity.hbm.xml"/>-->
  19. <mapping package="model"/>
  20. <mapping class="model.User"/>
  21. </session-factory>
  22. </hibernate-configuration>
  23.  
  24.  
  25. ENTITY КЛАСС
  26. @Entity
  27. @Table(name = "users", schema = "users_schema")
  28. public class User {
  29. private int id;
  30. private String name;
  31. private String password;
  32.  
  33. public User() {};
  34.  
  35. public User(int id, String name, String password) {
  36. this.id = id;
  37. this.name = name;
  38. this.password = password;
  39. }
  40.  
  41. @Id
  42. @Column(name = "id")
  43. public int getId() {
  44. return id;
  45. }
  46.  
  47. public void setId(int id) {
  48. this.id = id;
  49. }
  50.  
  51. @Basic
  52. @Column(name = "name")
  53. public String getName() {
  54. return name;
  55. }
  56.  
  57. public void setName(String name) {
  58. this.name = name;
  59. }
  60.  
  61. @Basic
  62. @Column(name = "password")
  63. public String getPassword() {
  64. return password;
  65. }
  66.  
  67. public void setPassword(String password) {
  68. this.password = password;
  69. }
  70.  
  71. @Override
  72. public boolean equals(Object o) {
  73. if (this == o) return true;
  74. if (o == null || getClass() != o.getClass()) return false;
  75.  
  76. User that = (User) o;
  77.  
  78. if (id != that.id) return false;
  79. if (name != null ? !name.equals(that.name) : that.name != null) return false;
  80. if (password != null ? !password.equals(that.password) : that.password != null) return false;
  81.  
  82. return true;
  83. }
  84.  
  85. @Override
  86. public int hashCode() {
  87. int result = id;
  88. result = 31 * result + (name != null ? name.hashCode() : 0);
  89. result = 31 * result + (password != null ? password.hashCode() : 0);
  90. return result;
  91. }
  92. }
  93.  
  94.  
  95.  
  96. MAPING FILE
  97. <?xml version='1.0' encoding='utf-8'?>
  98. <!DOCTYPE hibernate-mapping PUBLIC
  99. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  100. "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
  101. <hibernate-mapping>
  102.  
  103. <class name="model.User" table="users" schema="users_schema">
  104. <id name="id" column="id"/>
  105. <property name="name" column="name"/>
  106. <property name="password" column="password"/>
  107. </class>
  108. </hibernate-mapping>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement