0

我正在使用 Grails 2.1.0 和 Oracle 11。

我有一个域类,我试图连接到 Oracle 数据库中的表。当生成 SQL 以填充 list() 方法时,我得到 ORA-00918: column ambiguously defined。发生该错误是因为两次使用相同的别名请求了表的主键。这是生成的 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 <= ?

正如你所看到的 this_.benchmark_cusip 因为 benchmark1_4_0 出现了两次。

这是我的域类

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'}

}

控制器只是定义为 def scaffold = true。

我假设我有一些配置错误,但对于我的生活,我无法在我可以从办公室访问的有限数量的网站上找到它。

4

1 回答 1

1

通常我这样做:

class Benchmark {
  ...

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

}
于 2012-09-13T19:10:08.143 回答