为什么当应用程序托管在ec2实例上时,休眠而不是本地托管时,hibernate发送不正确的查询?

时间:2019-07-26 15:31:19

标签: sql oracle hibernate grails amazon-ec2

我已经设置了一个grails应用程序,该应用程序可以在具有适当结构(例如应用程序负载平衡器,目标组,RDS实例)的EC2实例上运行。除某些查询外,其他所有功能都有效,Hibernate似乎用其他字段,则发送错误的查询并导致无效的标识符错误。

我已经尝试了多种方法,从简单地从云形成模板重建堆栈到更改模板的结构,更改应用程序中的代码以尝试解决数据访问问题,更改数据库的结构,并在连接到RDS时在本地运行该应用程序。

这是域结构的一个例子

class Area {
  Set fences
  static hasMany = [
    fences: Fence
...
class Fence {
  Area location
  static belongsTo = [location: Area]
...

因此,代码示例为

def checkFences(Area area) {
  def fences = area.getFences()
...

然后,(缩短的)休眠查询将如下所示:

SELECT fences0_.area_id       AS area_id2_36_0_,
  fences0_.location_id        AS location_id3_38_0_,
  fence1_.id                  AS id1_8_1_,
  fence1_.location_id         AS location_id11_8_1_,
  fence1_.locationDescription AS locationDescripti12_8_1_,
  fence1_.updateDate          AS updateDate20_8_1_
FROM Area_fences fences0_
INNER JOIN Fence fence1_
ON fences0_.location_id=fence1_.id

因此错误是

ORA-00904: "FENCES0_"."LOCATION_ID": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Error at Line: 26 Column: 4

有趣的是,在仍连接到RDS的情况下在本地运行应用程序时,一切运行正常。然后查询显示为

SELECT fences0_.area_id       AS area_id2_36_0_,
  fences0_.fence_id           AS fence_id3_38_0_,
  fence1_.id                  AS id1_8_1_,
  fence1_.location_id         AS location_id11_8_1_,
  fence1_.locationDescription AS locationDescripti12_8_1_,
  fence1_.updateDate          AS updateDate20_8_1_
FROM Area_fences fences0_
INNER JOIN Fence fence1_
ON fences0_.fence_id=fence1_.id

因此,由于某种原因,休眠似乎在EC2实例上运行时用location_id切换了fence_id,但在本地运行时却没有,而且我也不知道为什么。

0 个答案:

没有答案