package example.entity; import javax.persistence.*; @Entity public class UserCredential implements java.io.Serializable { // Since we are using AccessType.FIELD, all member annotations // like @Id are applied to fields. @Id // name is the PK of this entity. private String name; private String password; protected UserCredential() { // Every entity bean must have a default public or protected constructor } public UserCredential(String name, String password) { if ( (name == null || name.length() == 0) || (password == null || password.length() == 0)) { throw new IllegalArgumentException("name or password is empty"); } this.name = name; this.password = password; } public boolean isMatchingPassword(String password) { return this.password.equals(password); } }