获取QuerySyntaxException:连接所需的路径。 我已经在实体中定义了路径。
@Entity
@Table( name = "datapoint_template_condition_action_map_details_map" )
@NamedQuery( name = "DatapointTemplateConditionActionMapDetailsMap.findAll", query = "SELECT d FROM DatapointTemplateConditionActionMapDetailsMap d" )
public class DatapointTemplateConditionActionMapDetailsMap implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY )
@Column( name = "iddatapoint_template_condition_action_map_details_map" )
private int iddatapointTemplateConditionActionMapDetailsMap;
@Temporal( TemporalType.TIMESTAMP )
@Column( name = "creation_time" )
private Date creationTime;
@Column( name = "is_disabled" )
private boolean isDisabled;
private int sequence;
@Column( name = "user_id" )
private int userId;
@Column( name = "condition_action_map_details_id" )
private int conditionActionMapDetailId;
@Column( name = "datapoint_template_id" )
private int datapointTemplateId;
@ManyToOne( fetch = FetchType.EAGER)
@JoinColumn( name = "condition_action_map_details_id", insertable = false, updatable = false )
private ConditionActionMapDetail conditionActionMapDetail;
public DatapointTemplateConditionActionMapDetailsMap() {
}
public int getConditionActionMapDetailId() {
return conditionActionMapDetailId;
}
public Date getCreationTime() {
return creationTime;
}
public int getDatapointTemplateId() {
return datapointTemplateId;
}
public int getIddatapointTemplateConditionActionMapDetailsMap() {
return iddatapointTemplateConditionActionMapDetailsMap;
}
public int getSequence() {
return sequence;
}
public int getUserId() {
return userId;
}
public boolean isDisabled() {
return isDisabled;
}
public void setConditionActionMapDetailId(int conditionActionMapDetailId) {
this.conditionActionMapDetailId = conditionActionMapDetailId;
}
public void setCreationTime(Date creationTime) {
this.creationTime = creationTime;
}
public void setDatapointTemplateId(int datapointTemplateId) {
this.datapointTemplateId = datapointTemplateId;
}
public void setDisabled(boolean isDisabled) {
this.isDisabled = isDisabled;
}
public void setIddatapointTemplateConditionActionMapDetailsMap(int iddatapointTemplateConditionActionMapDetailsMap) {
this.iddatapointTemplateConditionActionMapDetailsMap = iddatapointTemplateConditionActionMapDetailsMap;
}
public void setSequence(int sequence) {
this.sequence = sequence;
}
public void setUserId(int userId) {
this.userId = userId;
}
public ConditionActionMapDetail getConditionActionMapDetail() {
return conditionActionMapDetail;
}
public void setConditionActionMapDetail(ConditionActionMapDetail conditionActionMapDetail) {
this.conditionActionMapDetail = conditionActionMapDetail;
}
}
@Entity
@Table( name = "condition_action_map_details" )
@NamedQuery( name = "ConditionActionMapDetail.findAll", query = "SELECT c FROM ConditionActionMapDetail c" )
public class ConditionActionMapDetail implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY )
@Column( name = "idcondition_action_map_details" )
private int idconditionActionMapDetails;
@Column( name = "condition_action_map_description" )
private String conditionActionMapDescription;
@Column( name = "condition_action_map_name" )
private String conditionActionMapName;
@Temporal( TemporalType.TIMESTAMP )
@Column( name = "creation_time" )
private Date creationTime;
@Column( name = "customer_id" )
private int customerId;
@Column( name = "user_id" )
private int userId;
@Column( name = "conditions_id" )
private int conditionId;
@OneToMany(mappedBy="conditionActionMapDetail")
private List<ConditionActionMap> conditionActionMaps ;
public ConditionActionMapDetail() {
}
public String getConditionActionMapDescription() {
return conditionActionMapDescription;
}
public String getConditionActionMapName() {
return conditionActionMapName;
}
public int getConditionId() {
return conditionId;
}
public Date getCreationTime() {
return creationTime;
}
public int getCustomerId() {
return customerId;
}
public int getIdconditionActionMapDetails() {
return idconditionActionMapDetails;
}
public int getUserId() {
return userId;
}
public void setConditionActionMapDescription(String conditionActionMapDescription) {
this.conditionActionMapDescription = conditionActionMapDescription;
}
public void setConditionActionMapName(String conditionActionMapName) {
this.conditionActionMapName = conditionActionMapName;
}
public void setConditionId(int conditionId) {
this.conditionId = conditionId;
}
public void setCreationTime(Date creationTime) {
this.creationTime = creationTime;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public void setIdconditionActionMapDetails(int idconditionActionMapDetails) {
this.idconditionActionMapDetails = idconditionActionMapDetails;
}
public void setUserId(int userId) {
this.userId = userId;
}
public List<ConditionActionMap> getConditionActionMaps() {
return conditionActionMaps;
}
public void setConditionActionMaps(List<ConditionActionMap> conditionActionMaps) {
this.conditionActionMaps = conditionActionMaps;
}
}
在我春天的仓库类中我有
@Repository
public interface ActionRepository extends CrudRepository<Action, Integer> {
List<Action> findByCustomerId(int customerId);
@Query( "select camd.conditionActionMaps from DatapointTemplateConditionActionMapDetailsMap dtcamdm "
+ " join ConditionActionMapDetail camd "
+ " on dtcamdm.conditionActionMapDetail=camd.idconditionActionMapDetails "
+ " where dtcamdm.datapointTemplateId=:templateid and camd.conditionId=:conditionid" )
List<ConditionActionMap> findConditionActionMapForDatapointTemplateIdandConditionId(@Param( "templateid" ) int templateid,@Param( "conditionid" ) int conditionid);
// List<Action> findByActionData(String data);
// List<Action> findByActionTypeId(int typeId);
}
每次我尝试跑步时都会遇到以下异常
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [select camd.conditionActionMaps from com.vuelogix.collygo.data.entities.DatapointTemplateCo
nditionActionMapDetailsMap dtcamdm join ConditionActionMapDetail camd on dtcamdm.conditionActionMapDetail=camd.idconditionActionMapDetails where dtcamdm.datapointTemplateId=:t
emplateid and camd.conditionId=:conditionid]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:91)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:109)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:284)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:167)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328)
... 84 more
我根据hibernate文档在@ManytoOne中添加了路径。我搜索过类似的问题,但无法解决这个问题。
答案 0 :(得分:3)
将查询更改为
@Query( "select camd.conditionActionMaps from DatapointTemplateConditionActionMapDetailsMap dtcamdm "
+ " join dtcamdm.conditionActionMapDetail camd "
+ " where dtcamdm.datapointTemplateId=:templateid and camd.conditionId=:conditionid" )