Hi,
I've just found this project and I'm very excited about it, as I've fought
against ORM's before and have had a lot of difficulty with them.
I am just finding my way around jOOQ with a tiny database that contains two
tables Country and City.
With an ORM, I can display the info something lke this:
for (Country c : countries) {
// print country stuff
for (City city : c.getCities()) {
// print city stuff
}
}
However it sucks, because it does a separate select for each City
jOOQ looks cool because I can do something like and get everything in a
single select:
Result<Record> result =
create.select().from(COUNTRY).leftOuterJoin(CITY).onKey().fetch();
To achieve someting similar I was able to do:
Map<String, List<CountryRecord>> ctry =
result.intoGroups(COUNTRY.CODE, CountryRecord.class);
Map<String, List<CityRecord>> cities =
result.intoGroups(COUNTRY.CODE, CityRecord.class);
for (Map.Entry<String, List<CountryRecord>> entry :
ctry.entrySet()) {
CountryRecord cr = entry.getValue().get(0);
// print country stuff
List<CityRecord> thisCountriesCities =
cities.get(cr.getCode());
for (CityRecord c : thisCountriesCities) {
// print city stuff
}
Unfortunately that'd be a bit ugly to do inside a JSP for example, whereas
the first would be fairly straightforward as you could do a forEach with
another nested forEach.
Is this the best, or "right" way to do this? Or is there a nicer approach
that I'm missing?
I'm just trying to find the happy medium I guess - I've struggled most of
my career with the Object / Relational mismatch and I can't believe I'm
actually wanting to force this stuff back into objects, but there you go!
Andrew.
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.