package example; import javax.persistence.*; @Entity public class UserCredential implements java.io.Serializable { private String name; private String password; public UserCredential() { // Every entity bean must have a default public or protected constructor } public UserCredential(String name, String password) { this.name = name; this.password = password; validate(); } @Id // name is the PK of this entity. 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 void validate() { if (name == null || name.length() == 0) { throw new IllegalArgumentException("name is empty"); } if (password == null || password.length() == 0) { throw new IllegalArgumentException("password is empty"); } } public boolean isMatchingPassword(String password) { return this.password.equals(password); } }