java - BasicPathUsageException: Cannot join to attribute of basic type -
i using java 8 jpa (hibernate 5.2.1). have clause works perfectly, until introduce clause make use foreign key table values too.
i getting following error:
basicpathusageexception: cannot join attribute of basic type
i think problem related fact have join table, , not sure how create join using join table.
employee - employee_category - category
model (employee.java):
@manytomany(cascade = cascadetype.all, fetch=fetchtype.eager) @jointable ( name="employee_category", joincolumns={ @joincolumn(name="emp_id", referencedcolumnname="id") }, inversejoincolumns={ @joincolumn(name="cat_id", referencedcolumnname="id") } ) private set<category> categories;
model (category.java):
@id private string id;
jpa
when introduce following code, fails error above (i think problem new piece of code):
join<t, category> category = from.join("id"); predicates.add(criteriabuilder.like(category.<string>get("name"), "%" + searchquery + "%"));
this entire method:
protected list<t> findallcriteria(string[] orderbyasc, string[] orderbydesc, class<t> typeparameterclass, int firstresult, int maxresults, string searchquery) { criteriabuilder criteriabuilder = entitymanager.getcriteriabuilder(); criteriaquery<t> criteriaquery = criteriabuilder.createquery(typeparameterclass); // root<t> = criteriaquery.from(typeparameterclass); criteriaquery.select(from); // if (searchquery != null && searchquery.trim().length() > 0) { list<predicate> predicates = new arraylist<predicate>(); (string name : getcolumnnames(typeparameterclass)) { predicate condition = criteriabuilder.like(from.<string>get(name), "%" + searchquery + "%"); predicates.add(condition); } join<t, category> category = from.join("id"); predicates.add(criteriabuilder.like(category.<string>get("name"), "%" + searchquery + "%")); criteriaquery.where(criteriabuilder.or(predicates.toarray(new predicate[] {}))); } list<t> results = (list<t>) entitymanager.createquery(criteriaquery).setfirstresult(firstresult) .setmaxresults(maxresults).getresultlist(); return results; }
any appreciated.
solved:join category = from.join("categories");
Comments
Post a Comment