【发布时间】:2017-04-30 13:27:10
【问题描述】:
我正在尝试对不相关的实体 A 和 B 编写如下查询
Select a.x,a.y,a.z FROM A a ,B b Where
b.Parameter_Name='APPLICABLE_RULE_TYPE' And b.Parameter_KEY='MC' AND
b.Parameter_Value=a.rule_type And a.Rule_Status='ON' Order By Rule_Priority;
我无法弄清楚这应该如何写在 Spring 引导应用程序的 Repository 类中。
有人可以建议一种方法吗
提前致谢。
编辑:
我已经尝试将其作为原生查询,例如
@Query(value = "Select Rule_Id, Rule_Sql,S_System,S_Entity, s_table_name,Rule_Sql_Type "
+ "FROM rule_master TRM ,T_SYSTEM_CONFIG TSC Where"
+ " Tsc.Parameter_Name='APPLICABLE_RULE_TYPE' "
+ " And Tsc.Parameter_KEY= :systemType"
+ " AND Tsc.Parameter_Value=trm.rule_type "
+ " And Rule_Status='ON'"
+ " Order By Rule_Priority", nativeQuery = true)
public List<RuleMaster> findByRuleStatus(@Param("systemType" String systemType);
但出现此错误
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 17006, SQLState: null
o.h.engine.jdbc.spi.SqlExceptionHelper : Invalid column name
org.springframework.orm.jpa.JpaSystemException: could not execute query; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query
【问题讨论】:
-
我猜你正试图从你的存储库中只提取特定的列。在这里查看这个答案stackoverflow.com/questions/24710626/…
-
我在查询中有这个条件 b.Parameter_Value=a.rule_type 这就是为什么我要求加入不相关的实体。
标签: java hibernate spring-boot spring-data-jpa