繁体   English   中英

JPA 无法加入基本类型的属性

[英]JPA Cannot join to attribute of basic type

    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.Abs​​tractFromImpl.constructJoin(AbstractFromImpl.java:262) 处的基本类型的属性。 .join(AbstractFromImpl.java:255) at org.hibernate.ejb.criteria.path.Abs​​tractFromImpl.join(AbstractFromImpl.java:428) at com.vs.manifesto.logic.EntrepreneurCategoryBDL.getCategoryList(EntrepreDLneurCategory5) 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;
}

如何解决这个问题..?

您加入了基本类型的属性,因为您加入了字符串“category_id”

"Join<EntrepreneurCategory, Category> categoryJoin = entrepreneurCategoryRoot.join("category_id",JoinType.LEFT);"

您需要更改以加入一个类别,例如:

"Join<EntrepreneurCategory, Category> categoryJoin = entrepreneurCategoryRoot.join("category",JoinType.LEFT);"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM