• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting a single entity from a query

 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • 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 ?
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic