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 266335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:50:47+00:00 2026-05-11T22:50:47+00:00

There is a big design flaw here, but I’m having trouble solving it: The

  • 0

There is a big design flaw here, but I’m having trouble solving it:

The business need is a little involved so I’ll try to keep this simple.
We have a table with purchases, and a table for returns. When a return is made, we have to find match that return to the oldest purchase in the db, and record that in a “returns applied” table.

So, when I insert a Return, within that transaction, I need to apply the return to a purchase record.

As it stands now, we have a service that calls the repository for the insert. The service needs to know what the key is of that inserted record, so that it can finish the transaction by inserting an “applied” record using that key.

We’re basically stuck because my understanding is that a repository should not return this kind of data. Doesn’t this defeat the idea of the Repository being a collection?

What is the alternative?

CLARIFICATION:

We have a Purchase table, a Return table, and an Applied table

The applied table looks like this
purchaseId returnId qtyReturned

So when a return is inserted I need the id of a purchase (decided by some business rules) and the id of the newly inserted return.

  • 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-11T22:50:47+00:00Added an answer on May 11, 2026 at 10:50 pm

    I suppose the following according to your question:

    public class Purchase {
    
       // ReturnRepository plays the role of collaborator
       public Return returnMe(PurchaseRepository purchaseRepository, int quantity) {
           return purchaseRepository.returnPurchase(this, quantity);
       }
    
    }
    
    
    public class PurchaseRepositoryImpl implements PurchaseRepository {
    
        // returnd Purchase object has its id set up
        public Purchase getOldestPurchase() {
            // logic in order to get oldest purchase
        }
    
        public Return returnPurchase(Purchase purchase, quantity) {
            // logic in order to save a return record
            // Some ORM frameworks returns ids when a record is saved. In my case, Hibernate or NHibernate (.NET) fulfill ths requirement
    
            // Then purchaseId, returnId and quantity is saved in "returns applied" table
        }
    
    }
    
    
    public class PurchaseServiceImpl implements PurchaseService {
    
       // Injected through dependency injection
       private PurchaseRepository purchaseRepository;
    
       // Spring transaction boundary, for example
       // Notice returnPurchase method returns a Return object
       public Return returnPurchase(int quantity) {
           Purchase purchase = purchaseRepository.getOldestPurchase();
    
           return purchase.returnMe(purchaseRepository, quantity);
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

TextMate may be the best editor out there, but is has a big disadvantage:
This is likely by design for big teams with proper QA departments, but we
Do you think there is a big difference in for...in and for loops? What
I want to POST an URL using CURL and php. There is a big
Is there a master list of the Big-O notation for everything? Data structures, algorithms,
I am reviewing a big java application to see if there are any performance
With a seriously big .NET site/solution (100's of assemblies), are there any tools available
Report design, generation and maintenance isn't hard, but it is dull. We have a
I need to separate ViewModels in my MVC project from my business models (Data
Server virtualization is a big thing these days, so I'm tasked at work to

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.