This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Getting a single entity from a query

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following entity with a One to Many child object

I would like to get the parent record with one child record from this @OneToMany mapping so I have used the following query


This returns a list of objects and each position has two objects - an object of yearDepartment & departmentMonths.

Since I require a list of yearDepartments I iterate through this list with two objects and make it a list of yearDepartment with a single departmentMonths embedded inside.

Is there a way to get yearDepartment with just one departmentMonths inside the parent entity using the query/criterion/formula or any other means rather than manually processing it ?
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if "select yearDepartment from YearDepartment yearDepartment join ...." helps.

This should return a List of YearDepartment objects..
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats doesn't help since the list of YearDepartment still has a list of departmentMonths. In fact now I cannot do the following processing which I wish to avoid....

What I need is a list of YearDepartment with a single departmentMonths. This is why I had used the query.



 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't the "WHERE m.id=?" part of the query do this for you?
Isn't m.id unique here?
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic