This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting a single entity from a query

 
Jay Abrahm
Ranch Hand
Posts: 183
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic