У меня есть следующие классы publi c абстрактный класс User {
//^[a-zA-Z0-9]+$
//@Pattern(regexp="(^[a-zA-Z]+$)",message="Name should contain only letters")
@NotEmpty(message="FirstName is mandatory")
@Pattern(regexp="(^[a-zA-Z]{1,16})",message="First Name should contain only letters & can have maximum of 16 letters")
protected String firstName;
@Pattern(regexp="(^[a-zA-Z]{0,16})",message="Name should contain only letters")
protected String lastName ;
@Column(name = "phone")
@NotEmpty(message="Phone number is mandatory")
@Pattern(regexp="(^[0-9]{10})",message="Invalid Phone number")
protected String phoneNumber ;
protected String aadhaarNumber ;
protected Address address;
@DateTimeFormat(pattern="dd/MM/yyyy")
@Past(message="You can not become a owner since you are not yet born")
protected Date dob ;
@NotEmpty(message="If you do not wish to set password then how you will login in future?")
protected String password;
@NotEmpty(message="Cant you remember the password you just entered above ? Please enter same password.")
protected transient String repeatPassword ;
@Email(message="Not at all a email id")
protected String emailId ;
}
и его подкласс следующим образом @Entity publi c class Владелец расширяет User {
@Id
@GeneratedValue
private long pgOwnerId;
@ OneToMany (mappedBy = "myOwner", fetch = FetchType.EAGER) private Set myPGs;
+ геттеры и сеттеры
}
в слое dao , созданный интерфейс publi c интерфейс OwnerDao расширяет CrudRepository {
public List<Owner> findByPhoneNumber(String phoneNumber);
}
и сервисный уровень @Service publi c класса OwnerService {
@Autowired
private OwnerDao ownerDao;
public Owner createOwner(Owner owner)
{
return ownerDao.save(owner);
}
public Iterable<Owner> findAllOwners()
{
return ownerDao.findAll();
}
public List<Owner> findByPhoneNumber(String phoneNumber)
{
return ownerDao.findByPhoneNumber(phoneNumber);
}
}