Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- КОНФИГ
- <?xml version='1.0' encoding='utf-8'?>
- <!DOCTYPE hibernate-configuration PUBLIC
- "-//Hibernate/Hibernate Configuration DTD//EN"
- "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
- <hibernate-configuration>
- <session-factory>
- <property name="connection.url">jdbc:mysql://localhost:3306</property>
- <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="connection.username">root</property>
- <property name="connection.password">root</property>
- <property name="show_sql">true</property>
- <!-- DB schema will be updated if needed -->
- <property name="hbm2ddl.auto">update</property>
- <!--<mapping resource="model/UsersEntity.hbm.xml"/>-->
- <mapping package="model"/>
- <mapping class="model.User"/>
- </session-factory>
- </hibernate-configuration>
- ENTITY КЛАСС
- @Entity
- @Table(name = "users", schema = "users_schema")
- public class User {
- private int id;
- private String name;
- private String password;
- public User() {};
- public User(int id, String name, String password) {
- this.id = id;
- this.name = name;
- this.password = password;
- }
- @Id
- @Column(name = "id")
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
- @Basic
- @Column(name = "name")
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- @Basic
- @Column(name = "password")
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- User that = (User) o;
- if (id != that.id) return false;
- if (name != null ? !name.equals(that.name) : that.name != null) return false;
- if (password != null ? !password.equals(that.password) : that.password != null) return false;
- return true;
- }
- @Override
- public int hashCode() {
- int result = id;
- result = 31 * result + (name != null ? name.hashCode() : 0);
- result = 31 * result + (password != null ? password.hashCode() : 0);
- return result;
- }
- }
- MAPING FILE
- <?xml version='1.0' encoding='utf-8'?>
- <!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="model.User" table="users" schema="users_schema">
- <id name="id" column="id"/>
- <property name="name" column="name"/>
- <property name="password" column="password"/>
- </class>
- </hibernate-mapping>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement