hibernate.jpa.criteria.BasicPathUsageException: Cannot join to attribute of basic type
2022-09-04 08:45:32
I have two tables: and . There is one column same in both table i.e . But don't have any Hibernate mapping like or . Both table looks like-Tax
TaxRule
TAX_RULE_ID
OneToOne
OneToMany
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
@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 i.e . This column is common in both table.
I have following code in which I am joining both table on the column as follows:TAX_RULE_ID
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)