UserViewId主键代码块
package cn.cloudclass.bean;
import java.io.Serializable;
import javax.persistence.Embeddable;
@Embeddable
public class UserViewId implements Serializable{
private String name;
private String password;
private String type;
public UserViewId() {
}
public UserViewId(String name, String password, String type) {
super();
this.name = name;
this.password = password;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
UserView 代码块
package cn.cloudclass.bean;
import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name="userview")
public class UserView implements Serializable{
public UserView() {
}
public UserView(String name,String password,String type) {
this.id = new UserViewId(name,password,type);
}
@EmbeddedId
private UserViewId id;
public UserViewId getId() {
return id;
}
public void setId(UserViewId id) {
this.id = id;
}
}
由于视图无法自动创建,只能后期引用,所以在测试前必须在数据库准备好所需的表后再测试,否则会报异常。