Announcement Announcement Module
No announcement yet.
Design issue with JPA inheritance, Spring Roo and Spring Data JPA Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Design issue with JPA inheritance, Spring Roo and Spring Data JPA


    I am currently working on a Spring Roo/JPA application and I recently switched to a domain model based upon JPA inheritance. To sum up my domain model, I have an abstract Member entity that is subclassed by two entities: Male and Female.

    In all of my Spring MVC controllers, I would like to avoid always injecting two service dependencies (one that would deal with Male entities and the other with Female entities). I'd rather have one MemberService service (together with a corresponding MemberRepository) that would return either a Male instance or a Female instance.

    Is the above possible using Spring Roo annotations such as this one:
    @RooService(domainTypes = { Member.class })
    or that one?
    @RooJpaRepository(domainType = Member.class)
    For instance, will this (from MemberRepository)
    Member findByEmail(String email);
    return an object that I can cast to either the Female or Male type?

    More generally, what are the best practices to deal with entity inheritance at the level of Spring controllers and Spring services?

    Thanks in advance,