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;
}
}
由于视图无法自动创建,只能后期引用,所以在测试前必须在数据库准备好所需的表后再测试,否则会报异常。

本文介绍了一个基于Java的实体类UserView及其ID类UserViewId的设计实现,这两个类利用了JPA注解来定义数据库映射关系,并强调了在进行测试之前需要确保数据库中存在相应的表结构。
116

被折叠的 条评论
为什么被折叠?



