Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

limiting collection result size

 
Steve Kritzler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have a one-to-many relationship that I'm trying to build a query on, where I limit the number of rows returned in the collection, not in the entire result set. So for instance, where one dealership has many cars, I want a query that returns all dealerships and only 5 cars for each dealership. Can't get it to work, everything I try applies the "maxrows" to the entire result set.

Anyone have success with this or something similar?

Thanks in advance for your time and assistance...
 
Alfred Kemety
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with SQL query I would make a view that joins both tables and

SELECT dealer,MAX(car) WHERE ........ GROUP BY dealer, not sure how would this map to your case...
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this question about a specific ORM tool. Or is it more a JDBC question, where this thread should be moved?

Mark
 
Steve Kritzler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I'm actually trying to accomplish via Query by Example, or alternatively HQL.

At this point it looks like it's an explicit fetch against the collection (only), but it would be nice if I could do it in one query against the parent table.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And

"Steve K"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Basically, you need to add your real last name.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic