我们的应用程序存在轻微问题
我们正在尝试设置登录页面并使用glassfish运行以便进行身份验证,在我们的测试应用程序中我们可以执行此操作,但我们使用了表:
create table person(
username varchar(128) NOT NULL CONSTRAINT USER_PK PRIMARY KEY ,
password varchar(128) NOT NULL
..... many more fields here but are just for dob etc
);
和
create table usergroup(
username varchar(128) NOT NULL,
groupname varchar(128) NOT NULL,
CONSTRAINT GROUP_PK PRIMARY KEY(username, groupname),
CONSTRAINT USER_FK FOREIGN KEY(username) REFERENCES person(username)
ON DELETE CASCADE ON UPDATE RESTRICT
);
这很有效但是对于这个应用程序,我们试图让实体管理所有内容并创建表格,我们遇到的问题是我们设置的constraints
,我们如何在诱惑?
人员实体
@Entity
public class Person implements Serializable {
@ManyToOne
private Address address;
@OneToMany
private List<UserGroup> userGroupList;
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String firstName, surname, username, password, telephoneNumber, emailAddress,gender;
@Temporal(TemporalType.DATE)
private Date DateOfBirth;
public Person() {
}
public void addToGroups(UserGroup ug) {
this.userGroupList.add(ug);
}
和用户组实体
@Entity
public class UserGroup implements Serializable {
private static final long serialVersionUID = 1L;
@JoinColumn(name = "USERNAME", referencedColumnName = "USERNAME", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Person person;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String username, groupName;
我们需要约束和设置,因为我们无法使用glassfish正确验证