[英]hibernate.jpa.criteria.BasicPathUsageException: Cannot join to attribute of basic type
I have two tables: Tax
and TaxRule
.我有两个表:
Tax
和TaxRule
。 There is one column same in both table ie TAX_RULE_ID
.两个表中有一个相同的列,即
TAX_RULE_ID
。 But don't have any Hibernate mapping like OneToOne
or OneToMany
.但是没有像
OneToOne
或OneToMany
这样的 Hibernate 映射。 Both table looks like-两张桌子看起来都像-
TAX税
@Id
@Column(name = "TAX_RATE_ID")
private Long taxRateId;
@Column(name = "TAX_RULE_ID")
private Long taxRuleId;
@Column(name = "TAX_TYPE")
private String taxType;
TAX_RULE TAX_RULE
@Id
@Column(name = "TAX_RULE_ID")
private Long taxRuleId;
@Column(name = "TAX_CD")
private String TaxCode;
@Column(name = "STATE")
private String state;
I am trying to fetch data on the key ie TAX_RULE_ID
.我正在尝试获取密钥上的数据,即
TAX_RULE_ID
。 This column is common in both table.此列在两个表中都是通用的。 I have following
Hibernate
code in which I am joining both table on the TAX_RULE_ID
column as follows:我有以下
Hibernate
代码,其中我在TAX_RULE_ID
列上加入了两个表,如下所示:
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<String[]> cQuery = criteriaBuilder.createQuery(String[].class);
Root<Tax> taxRoot = cQuery.from(Tax.class);
cQuery.multiselect(taxRateRoot.get("taxType"), taxRateRoot.get("taxRate"));
List<Predicate> predicates = new ArrayList<>();
Join<Tax, TaxRule> join = taxRoot.join("taxRuleId");
.....rest of the code.
I am getting following Exception on the join point:我在连接点上收到以下异常:
org.hibernate.jpa.criteria.BasicPathUsageException: Cannot join to attribute of basic type
at org.hibernate.jpa.criteria.path.AbstractFromImpl.constructJoin(AbstractFromImpl.java:270)
at org.hibernate.jpa.criteria.path.AbstractFromImpl.join(AbstractFromImpl.java:263)
at org.hibernate.jpa.criteria.path.AbstractFromImpl.join(AbstractFromImpl.java:436)
at com.iclsystems.base.dao.TaxRateDAOImpl.getTaxTypeForApplicableWorkOrderTax(TaxRateDAOImpl.java:31)
at com.iclsystems.base.businessObjects.TaxLookupBOImpl.getTaxTypeForApplicableWorkOrderTax(TaxLookupBOImpl.java:53)
at com.iclsystems.base.businessObjects.TaxLookupBOImpl.getWorkOrderTaxLookup(TaxLookupBOImpl.java:29)
at com.iclsystems.test.eventhandler.base.TaxLookupBOTest.testTaxLookupBO(TaxLookupBOTest.java:52)
You cannot use the @Join
annotation for a basic property (eg, an attribute with a simple @Column
mapping).您不能将
@Join
注释用于基本属性(例如,具有简单@Column
映射的属性)。 @Join
is for associations: @Join
用于关联:
You need to remove this line, as the taxRuleId
is already fetched from the database:您需要删除这一行,因为
taxRuleId
已经从数据库中获取:
Join<Tax, TaxRule> join = taxRoot.join("taxRuleId");
If you want to join the TaxRule table, you need to replace the:如果要加入TaxRule表,需要替换:
@Column(name = "TAX_RULE_ID")
private Long taxRuleId;
with a many-to-one association:多对一关联:
@ManyToOne
@JoinColumn(name = "TAX_RULE_ID")
private TaxRule raxRule;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.