java - Spring Data JPA Criteria Join with child -
i working spring boot - spring data jpa in postgresql database. need know if possible spring data jpa. have classes these:
@entity @inheritance(strategy = inheritancetype.table_per_class) public abstract class product { @id private string id; private string name; ... } @entity public class fridge extends product { private integer capacity; ... } @entity public class offer { @id private long id; .... @jsonignoreproperties({"hibernatelazyinitializer", "handler"}) @manytoone(fetch = fetchtype.eager) @joincolumn(name="product_id") private product product; ... }
when trying build criteria specification, try do:
@override public predicate topredicate(root<offer> root, criteriaquery<?> criteriaquery, criteriabuilder criteriabuilder) { string key; join<offer, fridge> join = root.join("product", jointype.left); path<string> expression = join.get(key); ...
i have exception, , console says:
java.lang.illegalargumentexception: unable locate attribute the given name [capacity] on managedtype [my.app.product]
as can see, seems binding parent class and, since attribute not present in parent, fails. there way join children? because other approach create big table product attributes, cause big amount of innecesary columns in each entry...
thanks in advance!
Comments
Post a Comment