Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8619003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:14:27+00:00 2026-06-12T06:14:27+00:00

I am currently working on a Spring Roo/JPA application and I recently switched to

  • 0

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 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:14:29+00:00Added an answer on June 12, 2026 at 6:14 am

    I think the best way is to provide a repository for Male and another for Female
    using:

    repository jpa --interface ~.repository.MaleRepository --entity ~.domain.Male
    repository jpa --interface ~.repository.FemaleRepository --entity ~.domain.Female
    

    you get:

    @RooJpaRepository(domainType = Female.class)
    public interface FemaleRepository {
    }
    
    @RooJpaRepository(domainType = Male.class)
    public interface MaleRepository {
    }
    

    then you create the service layer for the application for these models (a service for each model)

    service --interface ~.service.MaleService --entity ~.domain.Male
    service --interface ~.service.FamaleService --entity ~.domain.Female
    

    and then you get:

    @RooService(domainTypes = { Male.class })
    public interface MaleService {
    }
    
    @RooService(domainTypes = { Female.class })
    public interface FemaleService {
    }
    

    This is assuming that your Male and Female objects have different responsibility so is needed to separate it in different classes, by the name you gave them (Male and Female) i think they don’t, but i don’t know your business logic and of course this is just an example (but how faithful is to your real problem?).

    The idea of inheritance is not only to share common functionality to “is-a” descendants but preserve the sense of the OO logic, when i say that i mean, in this case for example, you could resolve the problem with an attribute called sex if Male and Female have the same attributes; if this is not the case then wont be painful to create different repositories and services for those specialized objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

currently I am working on a spring based application. I do have some unit
I am currently working on securing a web application using spring-security 3.0. I have
I have a Spring/Hibernate web application (currently working fine on Tomcat) that I am
Im currently working on a grizzly, spring and jersey project and i have encountered:
Currently working on a Spring 2.5 web application, looks as if the business has
I am currently working on a spring portlet mvc 3 project. I have a
I'm currently working on a Spring MVC application and as I mapped, within the
I'm currently working on a web application using Spring MVC, and I use the
I am currently working on an application utilizing Guice / JPA / Hibernate to
I'm developing an application in Spring 3.0.5 and Hibernate 3.6.2, and currently i'm working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.