Polymorfic select

21 views
Skip to first unread message

Marvin Froeder

unread,
Nov 27, 2016, 4:43:57 AM11/27/16
to Querydsl
Hello there,

I'm using querydsl-sql and I would like to know if there is any way to select on a class subtypes.

I have one column on my database that contains the resulting type, I wonder what is the suggested way to map this...


Right now, I select both objects and choose later, like this:

 public List<Ingredient> ingredients(TenantID tenant, String id) {
 
return sqlFactory.newSelect(tenant, i)
 
.select(i.dtype,
 
new PIngredient(i.id, i.name, i.description, i.category),
 
new PAlternative(i.id, i.name, i.description, i.category, i.quantity, i.options))
 
.where(i.productId.eq(id))
 
.orderBy(i.category.asc(), i.name.asc())
 
.fetch()
 
.stream()
 
.map(tuple -> findIngredient(tuple))
 
.collect(Collectors.toList());
 
}


Reply all
Reply to author
Forward
0 new messages