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

  • SEARCH
  • Home
  • 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 7551503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:30:44+00:00 2026-05-30T10:30:44+00:00

I have one class named Question and another named StudentDriver . StudentDriver have a

  • 0

I have one class named Question and another named StudentDriver. StudentDriver have a list of questions. Since both classes are aggregate roots they have their own repository.

When I am going to add a new question, should the StudentDriver class have a method named addQuestion()? And would I merge the studentdriver object through the studentdriver repository, or would I persist the question with the question repository? If I persist it with question repository then the list of questions belonging to a studentdriver would not contain the newly added question until I refresh it from the database.

I don’t understand the connection between the two aggregate root objects and how I am going to model it correctly.

I am using JPA.

  • 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-05-30T10:30:46+00:00Added an answer on May 30, 2026 at 10:30 am

    Looks like you have two options:

    1) Two aggregate roots. Adding new question would look like this:

    StudentDriver student = studentsRepository.findById(id);
    Question question = someFactory.CreateForStudent(student);
    questionsRepository.Persist(question);
    

    And getting all questions for a student will be a responsibility of the questions repository:

    IList<Question> studentQuestions = questionsRepository.findByStudent(student);
    

    Essentially you have a persistent unidirectional relationship from question to student: Question-belongs-to-StudentDriver (many-to-one).

    2) One aggregate root. StudentDriver is a root of the aggregate that contains list of questions. Adding new question would look like this:

    StudentDriver student = studentsRepository.findById(id);
    student.addNewQuestion("Should you stop on a red light?", "Yes");
    studentsRepository.Persist(student);
    

    To get all questions for a student you would use something like:

    IList<Question> studentQuestions = student.GetAllQuestions();
    

    The choice between two options depends on the information that is missing from the OP. Good way to identify aggregate root is to look at a lifecycle logic. Questions like

    • Can Question exist without corresponding Student?
    • Can Question be ‘reassigned’ from one Student to another?
    • When you delete/archive Student, should all Questions also be deleted?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 questions: suppose we have one entity named class and another called
Suppose I have a class named Data . Another class annotates one of its
I have one grails application.In that I have one model class named Book. From
i am facing one problem.i have a class named ReportingService and it should be
I have an IPAddress class which has one property named ip and in its
I have a General Class named MyGeneralClass: public MyGeneralClass<T> { public List<T> Data {get;
I have an Class that is named Show one of the properties Country is
I have one managedobject class Metrics, which has an attribute metricType. metricType is another
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have two tables, one Company and one Employee: class Company(models.Model): name = models.CharField(max_length=60)

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.