package xyz.acmer.entity.user;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

/**
 * 用户基本信息表
 * Created by hypo on 16-2-2.
 */
@Entity(name = "user")
public class User{

    private Integer userId;
    private String userName;
    private String nickName;
    private String email;
    private String password;

    /**
     * 账户铜币数
     */
    private Integer balance;


    public User(String userName, String email, String password) {
        this.userName = userName;
        this.email = email;
        this.password = password;
    }

    public User(String userName, String nickName, String email, String password) {
        this.userName = userName;
        this.nickName = nickName;
        this.email = email;
        this.password = password;
    }

    @Id
    @GeneratedValue
    public Integer getUserId() {
        return userId;
    }

    @Column(name = "user_name", nullable = false, unique = true, length = 20)
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Column(name = "user_nickname", length = 30)
    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    @Column(name = "email", nullable = false, unique = true)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "password", nullable = false)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Column(name = "balance", nullable = false)
    public Integer getBalance() {
        return balance;
    }

    public void setBalance(Integer balance) {
        this.balance = balance;
    }
}

@@ -50,22 +50,17 @@
 istence.
-Column
+*
 ;%0Aimport
@@ -68,98 +68,43 @@
 java
-x.persistence.Entity;%0Aimport javax.persistence.GeneratedValue;%0Aimport javax.persistence.Id
+.util.HashSet;%0Aimport java.util.Set
 ;%0A%0A/
@@ -395,16 +395,42 @@
 lance;%0A%0A
+    public User() %7B%0A    %7D%0A
 %0A    pub
@@ -819,31 +819,134 @@
     
-@Id%0A    @GeneratedValue
+private Set%3CUserAccount%3E userAccounts = new HashSet%3CUserAccount%3E();%0A%0A    @Id%0A    @GeneratedValue%0A    @Column(name = %22user_id%22)
 %0A   
@@ -2036,11 +2036,591 @@
 e;%0A    %7D
+%0A%0A    @OneToMany(cascade = CascadeType.ALL, mappedBy = %22user%22)%0A    public Set%3CUserAccount%3E getUserAccounts() %7B%0A        return userAccounts;%0A    %7D%0A%0A    public void setUserAccounts(Set%3CUserAccount%3E userAccounts) %7B%0A        this.userAccounts = userAccounts;%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) return true;%0A        if (o == null %7C%7C getClass() != o.getClass()) return false;%0A%0A        User user = (User) o;%0A%0A        return userId.equals(user.userId);%0A%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return userId.hashCode();%0A    %7D
 %0A%7D%0A

update user