Hibernate 如何将ID映射到Grails中的不同列?
当我在域类中有ID时,它工作得很好Hibernate 如何将ID映射到Grails中的不同列?,hibernate,grails,gorm,Hibernate,Grails,Gorm,当我在域类中有ID时,它工作得很好 class Book { int id String bookAuthor static constraints = { bookAuthor blank: false, maxSize:30 } static mapping = { version false id generator: 'sequence', params: [sequenc
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|
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
错误|
2014-12-27 00:16:01293[http-bio-8080-exec-4]错误spi.SqlExceptionHelper-ORA-00904:“这是”B“
OOK_ID”:无效标识符
错误|
2014-12-27 00:16:01412[http-bio-8080-exec-4]错误。GrailExceptionResolver-SqlSyntaxError
处理请求时发生异常:[GET]/gTunes/book/index
ORA-00904:“本书ID”:无效标识符
. 跟踪如下:
消息:ORA-00904:“此”.“图书ID”:无效标识符
直线法
->>445 | oracle.jdbc.driver.t4cttiore中的processError
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|396 |进程“”中存在错误
|879 |进程错误。在oracle.jdbc.driver.T4C8Oall中
|450 |在oracle.jdbc.driver.T4CTTIfun中接收
|192 | doRPC。在“
|531 | oracle.jdbc.driver.T4C8Oall中的doOALL
|207 | doall 8。在oracle.jdbc.driver.T4CPreparedStatement中
|884 |在“”中执行命令描述
|1167 | oracle.jdbc.driver.oracle语句中的ExecuteMayBeDescripte
|1289 |在“”中执行超时
|3584 |执行内部。在oracle.jdbc.driver.OraclePreparedStatement中
|3628 |在“”中执行
|1493 |执行。在oracle.jdbc.driver.OraclePreparedStatementWrapper中
|43 |在grails.orm.PagedResultList中
|15 |$tt|U索引。在test.myapp.BookController中
|189 | grails.plugin.cache.web.filter.PageFragmentCachingFilter中的doFilter
|63 | doFilter。在grails.plugin.cache.web.filter.AbstractFilter中
|1145 | java.util.concurrent.ThreadPoolExecutor中的runWorker
|615 |运行。在java.util.concurrent.ThreadPoolExecutor$Worker中
^744 |在java.lang.Thread中运行
更新:
moise2022的解决方案奏效了。我可以打开列表页。但是,在show页面中生成的${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">
到
那仍然不起作用
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>
URI:/gTunes/book/show/1Class:java.lang.illegalargumentException消息:命名捕获组缺少尾随“}”
grails app\views\book\show.gsp第527行附近
关于AbstractFilter.java的第527行
grails app\views\book\show.gsp第50行左右
47: 48: 49: 50: 51: 52: 53:
使用name参数从默认id更改名称
static mapping = {
id generator: 'sequence',
params: [sequence:'s_book_seq'],
name: 'bookId'
}
检查文档并阅读此@johnsam我想因为您没有使用默认的id
name grails不知道使用什么id。你必须告诉它身份证是什么<代码>
谢谢,我也明白了。但仍然无法使删除生效。查看我的更新。我猜您的控制器中有一个名为“删除”的操作。如果是这样,您可以尝试使用
删除记录,不需要发回整个对象。此外,[g:form][1]文档可能会有帮助[1]是。我明白了。但我无法找出正确的语法来实现这一点。gsp代码是由generate forms命令生成的。我认为有必要对g:formurl属性进行一些调整,但不确定如何调整。
static mapping = {
id generator: 'sequence',
params: [sequence:'s_book_seq'],
name: 'bookId'
}