log.debug("get category list start "+id);
List<CategoryResponseView> usersViewList = new ArrayList<CategoryResponseView>();
long a=System.currentTimeMillis();
CriteriaBuilder builder = em.getCriteriaBuilder();
Metamodel metamodel=em.getMetamodel();
EntityType EntrepreneurCategory_=metamodel.entity(EntrepreneurCategory.class);
CriteriaQuery<Object[]> query = builder.createQuery(Object[].class);
Root<EntrepreneurCategory> entrepreneurCategoryRoot=query.from(EntrepreneurCategory.class);
Join<EntrepreneurCategory, Category> categoryJoin = entrepreneurCategoryRoot.join("category_id",JoinType.LEFT);
Join<EntrepreneurCategory, Cluster> clusterJoin = entrepreneurCategoryRoot.join("cluster_id",JoinType.LEFT);
List<Predicate> conditions = new ArrayList();
conditions.add(builder.equal(entrepreneurCategoryRoot.get("id"), id));
TypedQuery<Object[]> typedQuery = em.createQuery(query
.multiselect(entrepreneurCategoryRoot).where(conditions.toArray(new Predicate[] {}))
);
return usersViewList;
org.hibernate.ejb.criteria.BasicPathUsageException:无法加入 基本类型的属性 org.hibernate.ejb.criteria.path.AbstractFromImpl.constructJoin(AbstractFromImpl.java:262) 在 org.hibernate.ejb.criteria.path.AbstractFromImpl.join(AbstractFromImpl.java:255) 在 org.hibernate.ejb.criteria.path.AbstractFromImpl.join(AbstractFromImpl.java:428) 在 com.vs.manifesto.logic.EntrepreneurCategoryBDL.getCategoryList(EntrepreneurCategoryBDL.java:55) 在 com.vs.manifesto.scoreboard.services.CategoryServices.getCategoryList(CategoryServices.java:44)
以下是模型类元素
@ManyToOne
@JoinColumn(name = "category_id",referencedColumnName="id",insertable=false,updatable=false)
private Category category;
private String category_id;
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
如何解决这个问题..?
答案 0 :(得分:0)
你加入了基本类型的属性,因为你加入了字符串“category_id”
"Join<EntrepreneurCategory, Category> categoryJoin = entrepreneurCategoryRoot.join("category_id",JoinType.LEFT);"
您需要更改以加入如下类别:
"Join<EntrepreneurCategory, Category> categoryJoin = entrepreneurCategoryRoot.join("category",JoinType.LEFT);"