我有一个命名查询,它为Sybase 15数据库的调用生成交叉连接。我想我需要重新格式化我的查询以使用连接但无法找出所需的语法。对象及其映射如下所示
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "workflow_type_id", nullable = false)
private WorkflowType workflowType;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
@JoinColumn(name = "workflow_def_id", nullable = false, updatable = false)
private WorkflowDef workflowDef;
我的命名查询是
@NamedQuery(name = "WorkflowInstance.hasStatus", query = "SELECT wi.id FROM WorkflowInstance wi WHERE wi.deal.id = :dealId AND wi.workflowDef.workflowType.systemKey = :wfTypeName AND wi.status IN (:statuses)")
这会引发错误
2015-01-26 16:27:24,237 DEBUG [http-8080-3] util.SQLStatementLogger -
select
workflowin0_.wf_instance_id as col_0_0_
from
tbl_wf_instance workflowin0_ cross
join
tbl_workflow_def workflowde1_ cross
join
tbl_lkp_workflow_type workflowty2_
where
workflowin0_.workflow_def_id=workflowde1_.workflow_def_id
and workflowde1_.workflow_type_id=workflowty2_.workflow_type_id
and workflowin0_.deal_id=?
and workflowty2_.name=?
and (
workflowin0_.status in (
?
)
)
2015-01-26 16:27:24,238 TRACE [http-8080-3] type.NullableType - binding' 60001972'参数:1 2015-01-26 16:27:24,239 TRACE [http-8080-3] type.NullableType - binding' CREDIT'参数:2 2015-01-26 16:27:24,240 DEBUG [http-8080-3] type.EnumType - Binding' 2'参数:3 2015-01-26 16:27:24,277 WARN [http-8080-3] util.JDBCExceptionReporter - SQL错误:102,SQLState:42000 2015-01-26 16:27:24,278 ERROR [http-8080-3] util.JDBCExceptionReporter - 错误的语法在' cross'附近。
我在持久性单元中使用以下内容
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false"/>
<property name="databasePlatform" value="org.hibernate.dialect.SybaseASE15Dialect"/>
</bean>
</property>
有人可以告诉我哪里出错吗?
答案 0 :(得分:0)
不支持CROSS JOIN
语法,但您只需删除关键字CROSS
即可。语义不会发生变化。
答案 1 :(得分:0)
JOIN
与INNER JOIN
相同。问题是ANSI样式连接不需要ON
子句。如果您确实需要笛卡尔积,那么只需为每个ON 1=1
子句添加JOIN
。
答案 2 :(得分:0)
最终,这似乎是旧的hibernate库的问题,而不是实体上定义的映射。现在,升级库会导致为sybase后端生成正确的sql。
答案 3 :(得分:-1)
这是因为方言,尝试改变其他版本的方言。 例如在hibernate.cfg.xml中,如果您使用Sybase ...
解决方法是使用SybaseASE15Dialect而不是SybaseASEDialect