Hey Lucas

I want to fetch one to many records. 
Employee --> Addresses

There is not any fixed relationship among these 2 tabes. Relation from 
Employee to Addresses comes to me at runtime.
Like, it can be Employee.ID = Addresses.EMP_ID 
OR 
Employee.USER_ID = Addresses.USER_ID


Logic - I have adopted very simple and manual approach. First, loading 
Employee (with where condition) and then loading List of Addresses for each 
Employee record.

Other than JOOQ generated classes for Employee and Addresses, I am also 
maintaining my POJOs. So, in my Employee POJO, I have 
List<addresses>.

SelectQuery jooqQuery = ctx.selectQuery();
jooqQuery.addFrom(jooq.generated.Employee);
jooqQuery.addConditions(Where jooq.generated.Employee.ID = EMP 1);


Problem: 
I need my query results as List of Employee like -
List<jooq.generated.employee> results = 
jooqQuery.fetchInto(jooq.generated.Employee);

But, it gives ClassCast error. In actual it is expecting to collect in 
Result<record>

I need List<jooq.generated.employee> because, further I want to iterate 
this Employee List to load List<addresses> after implementing 
'Relationship' that came to me at runtime, like-

Condition embeddedCondition = 
jooq.generated.Employee.TableField.eq(jooq.generated.Addresses.TableField)

List<my_addresses_pojo.> addressesList = create.select 
<http://disq.us/url?url=http%3A%2F%2Fcreate.select%3Alsbh2G1Kh0zVtkqxw0vWhRdhvxE&cuid=2119647>
().from(jooq.generated.Addresses).where(embeddedCondition).fetchInto(my_addresses_pojo.class);


And then, I will fill it like -
my_EmployeePojo.setAddresses(addressesList);


Thanks
Vivek

-- 
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/d/optout.

Reply via email to