我得到这样的域类:

class Offer {

    Property property
    Building building
    ExternalSystem externalSystem
    OfferStatus status
    Double offerPrice
    String currency
    String description
    String adventages
    Date offerDisponibility
    OfferNature offerNature
    Surfaces surfaces

    static hasMany = [units: Unit]

    static constraints = {
        building nullable: true
        externalSystem nullable: true
        description nullable: true
        adventages nullable: true
    }
}

当将其填充到 Controller 中时:
def offer = new Offer()
offer.property = Property.get(1)
offer.building = Building.get(1)
offer.externalSystem = ExternalSystem.get(1)
offer.status = OfferStatus.get(1)
offer.offerPrice = 26860
offer.currency = 'EUR'
offer.description = 'WONDERFULL OFFER !'
offer.offerDisponibility = convertDate('12/04/2014')
offer.offerNature = OfferNature.read(1)
offer.surfaces = Surfaces.get(2)
offer.validate()

验证,保存或对此对象执行任何操作时,都会收到奇怪的行为。
这是唯一做到这一点的域对象域。

我得到两个不同的stacktrace,这是我问题中最奇怪的部分,第一次调用 Controller 时会出现第一个stacktrace:
| Error 2013-11-26 11:27:10,971 [http-bio-8080-exec-2] ERROR errors.GrailsExceptionResolver  - ArrayIndexOutOfBoundsException occurred when processing
 request: [GET] /Project/login/auth
0. Stacktrace follows:
Message: 0
    Line | Method
->>  116 | doCall    in com.project.security.LoginController$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    200 | 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
^    722 | run       in java.lang.Thread

第二个总是最后一个stacktrace:
| Error 2013-11-26 11:01:43,704 [http-bio-8080-exec-3] ERROR [/Project].[default]  - Servlet.service() for servlet [default] in context with path [/Project] threw exception [org.springframework.web.util.NestedServletException: Request processing failed; nested exception is groovy.lang.MissingMethodException: No signature of method: static java.lang.Math.max() is applicable for argument types: (java.lang.Integer, null) values: [4, null]
Possible solutions: max(int, int), max(double, double), max(float, float), max(long, long), min(int, int), wait()] with root cause
Message: No signature of method: static java.lang.Math.max() is applicable for argument types: (java.lang.Integer, null) values: [4, null]
Possible solutions: max(int, int), max(double, double), max(float, float), max(long, long), min(int, int), wait()
    Line | Method
->>  251 | doAppend              in org.apache.log4j.AppenderSkeleton
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|     66 | appendLoopOnAppenders in org.apache.log4j.helpers.AppenderAttachableImpl
|    206 | callAppenders . . . . in org.apache.log4j.Category
|    391 | forcedLog             in     ''
|    856 | log . . . . . . . . . in     ''
|    192 | logMessage            in org.slf4j.impl.GrailsLog4jLoggerAdapter
|    167 | error . . . . . . . . in     ''
|    213 | error                 in org.apache.commons.logging.impl.SLF4JLog
|    200 | 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
^    722 | run . . . . . . . . . in java.lang.Thread

那么哪个stacktrace是正确的呢?

我该如何解决?

如果不调用save()或validate()消息,则没有stacktrace。

添加failOnError:true不会更改堆栈跟踪。

制造 :
if (!offer.save()) {
    log.error offer.errors
}

没有改变堆栈跟踪。

谢谢阅读,

ite

最佳答案

经过数小时的研究,我终于解决了我的问题。

Property myProperty

不知道为什么,但是“属性”作为变量名(而不是域名类名)似乎是保留的关键字...

希望它会有用。

关于hibernate - Grails:保存对象时出错,很难理解,请勿使用 'property'关键字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20214511/

10-12 02:47