Imagine an application that consumes an external data stream and creates objects of this type:

public class Event {

  @OneToOne(cascade = CascadeType.ALL)
  private EventInfo info;

  @OneToOne(cascade = CascadeType.ALL)
  private EventSource source;



Later in the DAO:


In the data stream, every Event has a fully self-contained JSON representation of both the EventInfo and the EventSource.

This has been working fine, but now I need to refactor this code and ensure that EventSource entities are re-used, i.e. change to:

  @ManyToOne(cascade = ???)
  private EventSource source;

Now the question is this. Given that the external data-stream always contains a full representation, it is necessary to look-up EventSource in the database and re-set the value in the Event object prior to saving the Event entity.

What layer of the application should be responsible for the look-up?

  • I see the makings of a good question here, but I don't think there's quite enough information in your post to make it answerable. You haven't told us anything about your architecture, and I don't know what "receiving application" means. So I'm going to go ahead and close this and leave it on the site for a few days so that you can clarify it. – Robert Harvey May 13 at 14:54
  • In the meantime, assuming your architecture is reasonably "typical" (if there is such a thing in software development), I see no reason why you couldn't do this in your Data Access Layer. – Robert Harvey May 13 at 14:55
  • @RobertHarvey I clarified the question by removing the word "receiving", as that seemed to imply two different applications were involved. There is only one application, and the architecture is described in the opening line: "Imagine an application that consumes an external data stream and creates objects of [given type]". I put a lot of thought into omitting unnecessary details. Is there anything else I can clarify? Thanks – Alex R May 13 at 15:05
  • What kind of architecture are you using? Three-Tier? Model-View-ViewModel? – Robert Harvey May 13 at 15:05
  • basic Spring MVC with no complications – Alex R May 13 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.