防止某些东西被加入休眠状态

时间:2016-05-18 12:26:59

标签: java mysql hibernate

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "idUser")
public UserEntity getUserEntity() {
    return teacher;
}

public void setUserEntity(UserEntity idTeacher) {
    this.teacher = idTeacher;
}

以下代码位于我的数据模型中。我使用继承,并按以下方式查询此数据:

    Query query1 = session.createQuery("FROM GroupEntity");
    List<GroupEntity> groups = (List<GroupEntity>) query1.list();

问题是。它现在将加入所有使用信息。但我只想选择几件事。例如。只有用户名。而不是密码。

UserEnity下方:

@Entity
@Table(name = "User", schema = "", catalog = "")
@Inheritance(strategy = InheritanceType.JOINED)
public class UserEntity implements Serializable{
    private int idUser;
    private GroupEntity groupEntity;
    private String email;
    private String firstName;
    private String lastName;
    //ToDo Make this password secure!
    private String password;
    private boolean admin;
    private boolean teacher;

    public UserEntity(String email, String firstName, String lastName, String password, boolean admin, boolean teacher) {
        this.email = email;
        this.firstName = firstName;
        this.lastName = lastName;
        this.password = password;
        this.admin = admin;
        this.teacher = teacher;
    }

    public UserEntity() {

    }

    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "idUser")
    public int getIdUser() {
        return idUser;
    }

    public void setIdUser(int idUser) {
        this.idUser = idUser;
    }

    @Basic
    @Column(name = "email")
    public String getEmail() {
        return email;
    }

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

    @Basic
    @Column(name = "firstName")
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Basic
    @Column(name = "lastName")
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Basic
    @Column(name = "password")
    public String getPassword() {
        return password;
    }

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

    @Basic
    @Column(name = "admin")
    public boolean getAdmin() {
        return admin;
    }

    public void setAdmin(boolean admin) {
        this.admin = admin;
    }

    @Basic
    @Column(name = "teacher")
    public boolean getTeacher() {
        return teacher;
    }

    public void setTeacher(boolean teacher) {
        this.teacher = teacher;
    }

}

0 个答案:

没有答案