grails - Grails应用程序生成不正确的SQL

标签 grails gorm

我正在使用Grails 2.1.0和Oracle 11。

我有一个域类,我试图连接到Oracle数据库中的表。当生成SQL来填充list()方法时,我得到ORA-00918:列的定义不明确。发生错误是因为使用相同的别名两次请求了表的主键。这是生成的SQL:

select * from ( select this_.BENCHMARK_CUSIP as BENCHMARK1_4_0_, this_.acronym as acronym4_0_, this_.as_of_date as as3_4_0_, this_.ask_price as ask4_4_0_, this_.ask_yield as ask5_4_0_, this_.benchmark_cusip as benchmark1_4_0_, this_.bid_price as bid6_4_0_, this_.bid_yield as bid7_4_0_, this_.coupon as coupon4_0_, this_.coupon_frequency as coupon9_4_0_, this_.is_on_the_run as is10_4_0_, this_.last_update_time as last11_4_0_, this_.last_update_user as last12_4_0_, this_.maturity as maturity4_0_, this_.name as name4_0_, this_.price as price4_0_, this_.source as source4_0_, this_.yield as yield4_0_ from BENCHMARK this_ ) where rownum <= ?

如您所见,这是Benchmark1_4_0的this_.benchmark_cusip出现了两次。

这是我的 Realm 类(class)
class Benchmark {
    String benchmarkCusip
    String acronym
    String name
    Double coupon
    java.math.BigDecimal couponFrequency
    Date maturity
    String isOnTheRun
    Date asOfDate
    Double bidYield
    Double yield
    Double askYield
    Double bidPrice
    Double price
    Double askPrice
    String source
    String lastUpdateUser
    Date lastUpdateTime

static mapping = {
    table 'BENCHMARK'        
    version false
   columns{id column:'BENCHMARK_CUSIP', generated:'assigned'}

}

Controller 仅定义为def scaffold = true。

我以为我配置不正确,但是在我的生命中,我无法从办公室访问的站点数量有限。

最佳答案

通常我这样做:

class Benchmark {
  ...

  static mapping = {
    table 'benchmark'
    id column: 'benchmark_cusip', name: 'benchmarkCusip'
  }

}

关于grails - Grails应用程序生成不正确的SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12412897/

相关文章:

json - 无法在 Grails 2.1 中的 ExtJS 网格 (4.2.1) 中填充 JSON 数据

gorm - 如何按字母顺序检索列表的成员?

grails - 连接不懒惰的问题;)

grails - 根据某些条件取消/阻止域对象的保存?

grails - 按名称查找实例,其中查询是其名称的任意部分,Grails

grails - Grails性能测试错误:org.hibernate.StaleObjectStateException:行被另一个事务更新或删除

grails - 自定义插入和更新方法被自动保存击败

grails - 没有这样的属性:运行模式导出时出现类问题的developmentModeActive

Grails - 如何传递域对象和使用服务

grails - 在grails域类中禁用乐观锁定