当我在Domain类中拥有ID时,它工作正常
class Book {
int id
String bookAuthor
static constraints = {
bookAuthor blank: false, maxSize:30
}
static mapping = {
version false
id generator: 'sequence',
params: [sequence:'s_book_seq']
}
}
但是一旦我尝试将Id映射到BookId,
class Book {
int bookId
String bookAuthor
static constraints = {
bookAuthor blank: false, maxSize:30
}
static mapping = {
version false
id generator: 'sequence',
params: [sequence:'s_book_seq'], column :'bookId'
}
}
然后Grails将无法启动我的应用程序。如何将ID映射到不同的字段?
我得到的 error
是:
Error|
2014-12-27 00:16:01,293 [http-bio-8080-exec-4] ERROR spi.SqlExceptionHelper - ORA-00904: "THIS_"."B
OOK_ID": invalid identifier
Error |
2014-12-27 00:16:01,412 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver - SQLSyntaxErro
rException occurred when processing request: [GET] /gTunes/book/index
ORA-00904: "THIS_"."BOOK_ID": invalid identifier
. Stacktrace follows:
Message: ORA-00904: "THIS_"."BOOK_ID": invalid identifier
Line | Method
->> 445 | processError in oracle.jdbc.driver.T4CTTIoer
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 396 | processError in ''
| 879 | processError . . . . in oracle.jdbc.driver.T4C8Oall
| 450 | receive in oracle.jdbc.driver.T4CTTIfun
| 192 | doRPC . . . . . . . in ''
| 531 | doOALL in oracle.jdbc.driver.T4C8Oall
| 207 | doOall8 . . . . . . in oracle.jdbc.driver.T4CPreparedStatement
| 884 | executeForDescribe in ''
| 1167 | executeMaybeDescribe in oracle.jdbc.driver.OracleStatement
| 1289 | doExecuteWithTimeout in ''
| 3584 | executeInternal . . in oracle.jdbc.driver.OraclePreparedStatement
| 3628 | executeQuery in ''
| 1493 | executeQuery . . . . in oracle.jdbc.driver.OraclePreparedStatementWrapper
| 43 | <init> in grails.orm.PagedResultList
| 15 | $tt__index . . . . . in test.myapp.BookController
| 189 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
更新
moise2022的解决方案有效。我可以打开列表页面。但是,显示页面中生成的$ {bookInstance}是错误的。<g:link class="edit" action="edit" resource="${bookInstance}"><g:message code="default.button.edit.label" default="Edit" /></g:link>
而不是
<a href="/gTunes/book/edit/1" class="edit">Edit</a>
它生成了
<a href="/gTunes/book/edit" class="edit">Edit</a>
所以编辑导航打破了
更新
删除 我试图改变
<g:form url="[resource:bookInstance, action:'delete' ]" method="DELETE">
到
<g:form url="[resource:bookInstance, action:'delete', id:'${bookInstance.bookId}' ]" method="DELETE">
那仍然没有奏效。
URI:/gTunes/book/show/1Class:java.lang.IllegalArgumentExceptionMessage:named capturing group is missing trailing '}'
Around line 527 of grails-app\views\book\show.gsp
Around line 527 of AbstractFilter.java
Around line 50 of grails-app\views\book\show.gsp
47: <g:link class="edit" action="edit" id="${bookInstance.bookId}" ><g:message code="default.button.edit.label" default="Edit" /></g:link></td>48: <g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />49: </fieldset>50: </g:form>51: </div>52: </body>53:</html>