繁体   English   中英

休眠不使用带有内部连接的 where 子句

[英]hibernate not using where clause with inner join

这是我的代码摘录(我使用的是 XDoclet):

/**
 * @hibernate.class table="WIP_DISCRETE_JOBS"
 */
public class WipDiscreteJob extends AuditedObject
{
  private WipDiscreteJobStatus status;

  /**
   * @hibernate.many-to-one column="STATUS_TYPE"
   */
  public WipDiscreteJobStatus getStatus()
  {
    return status;
  }
}

/**
 * @hibernate.class
 *   table="apps.mfg_lookups"
 *   where="lookup_type = 'WIP_JOB_STATUS'"
 */
public class WipDiscreteJobStatus extends ManufacturingLookup
{
  /**
   * @hibernate.id column="LOOKUP_CODE"
   *   generator-class="assigned"
   */
  public Long getId()
  {
    return this.id;
  }

}

这是一些数据库定义:

APPS.MFG_LOOKUP (view)
Column Name  Pk  Data Type            Null?
LOOKUP_TYPE      VARCHAR2 (30 Byte)   N
LOOKUP_CODE      NUMBER               Y

WIP_DISCRETE_JOBS
Column Name  Pk  Data Type            Null?
STATUS_TYPE  N   NUMBER               Yes       

当我查询 WipDiscreteJob 并尝试获取结果计数(使用 Criterias)时,部分 SQL 看起来像

select count(*) as y0_ 
from WIP_DISCRETE_JOBS this_ 
inner join apps.mfg_lookups       wipdiscret2_ on this_.STATUS_TYPE=wipdiscret2_.LOOKUP_CODE 
inner join WIP_ENTITIES           wipentity1_  on this_.WIP_ENTITY_ID=wipentity1_.WIP_ENTITY_ID 
inner join WIP_SCHEDULE_GROUPS    wipschedul4_ on this_.SCHEDULE_GROUP_ID=wipschedul4_.SCHEDULE_GROUP_ID 
inner join INV.MTL_SYSTEM_ITEMS_B item3_       on this_.PRIMARY_ITEM_ID=item3_.INVENTORY_ITEM_ID and this_.ORGANIZATION_ID=item3_.ORGANIZATION_ID 
where wipentity1_.WIP_ENTITY_NAME is not null
  and wipdiscret2_.LOOKUP_CODE=3 
  and item3_.PLANNER_CODE='A5'
  and wipschedul4_.SCHEDULE_GROUP_NAME='Area 2'

我在运行它时收到“无效数字”错误。 但是当我从类中添加“where”子句时......

select count(*) as y0_ 
from WIP_DISCRETE_JOBS this_ 
inner join apps.mfg_lookups       wipdiscret2_ on this_.STATUS_TYPE=wipdiscret2_.LOOKUP_CODE  AND lookup_type = 'WIP_JOB_STATUS'
inner join WIP_ENTITIES           wipentity1_  on this_.WIP_ENTITY_ID=wipentity1_.WIP_ENTITY_ID 
inner join WIP_SCHEDULE_GROUPS    wipschedul4_ on this_.SCHEDULE_GROUP_ID=wipschedul4_.SCHEDULE_GROUP_ID 
inner join INV.MTL_SYSTEM_ITEMS_B item3_       on this_.PRIMARY_ITEM_ID=item3_.INVENTORY_ITEM_ID and this_.ORGANIZATION_ID=item3_.ORGANIZATION_ID 
where wipentity1_.WIP_ENTITY_NAME is not null
  and wipdiscret2_.LOOKUP_CODE=3 
  and item3_.PLANNER_CODE='A5'
  and wipschedul4_.SCHEDULE_GROUP_NAME='Area 2'

并手动运行它,它运行良好。 这只是 Hibernate 中的一个错误还是我遗漏了什么? 如何让 Hibernate 添加“where”子句?

您需要将status.lookup_type = 'WIP_JOB_STATUS'添加到您的标准列表中。

您尚未提供查询,因此无法修复该部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM