gpt4 book ai didi

hibernate - 如何将ID映射到Grails中的其他列?

转载 作者:行者123 更新时间:2023-12-02 14:42:25 25 4
gpt4 key购买 nike

当我在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>

最佳答案

使用名称参数可从默认ID更改名称。

static mapping = {
id generator: 'sequence',
params: [sequence:'s_book_seq'],
name: 'bookId'
}

检查文档 here并阅读此 post

关于hibernate - 如何将ID映射到Grails中的其他列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27664626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com