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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:30:59+00:00 2026-05-13T18:30:59+00:00

Can this ever make sense? Say I need to fetch an object from the

  • 0

Can this ever make sense?

Say I need to fetch an object from the DB which has a relation to another object (represented by a foreign key in the DB, and by a composition in my domain object). If in my first DAO I fetch the data for object 1, then call the dao for object 2, and finally (from within the first DAO, call the setter in object 1 and give it the previously fetched object 2).

I know I could do a join instead, but it just seems more logical to me to decouple the functionality (which is why I am skeptical about calling one dao from another). Or should I move some of the logic to the service layer?

Thanks

Update: I think I solved the problem with help from the answers: all I needed to do was add the following to my mapping of Object 1:

<one-to-one name="Object2" fetch="join"
        class="com...Object2"></one-to-one>

I didn’t have to change anything else. Thanks for the help!

  • 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-13T18:30:59+00:00Added an answer on May 13, 2026 at 6:30 pm

    In reading this I can only conclude that most likely, you’re doing it wrong.. 😉

    If you setup your mappings right between ObjectA and ObjectB (could be OneToOne, OneToMany or ManyToMany), Hibernate will (lazy)load the reference from A to B automatically.
    This will eliminate the need to query the second DAO, and set the ObjectB reference in ObjectA.

    Take this one step further and you might not even need the DAO for ObjectB!

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

Sidebar

Related Questions

The following will make more sense if you have ever played minecraft. Since many
Can this be done? It seems like this should be possible. In general, I
Can this be done in JavaScript? type == 1 ? function1() : function2();
Can this be simplified to a one liner? Feel free to completely rewrite it
Can this method work? public String sayHello(){ return Hello.jsp?name= + laala; } I am
Can this <%= link_to 'Item', {:controller => items, :action => update, :id => @item,
Can this be done? Basically I work on multiple projects using xampp, and I
How can this code compile? The code below in the operator int CAN access
How can this be done more elegant and without creating new objects? List<Move> playerMoves
in what way can this be programmed. a UI box that displays random number

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.