Hibernate Grails:保存对象时出错,难以理解,don';t使用';财产';关键词

Hibernate Grails:保存对象时出错,难以理解,don';t使用';财产';关键词,hibernate,validation,grails,save,stack-trace,Hibernate,Validation,Grails,Save,Stack Trace,我得到了这样一个域类: class Offer { Property property Building building ExternalSystem externalSystem OfferStatus status Double offerPrice String currency String description String adventages Date offerDisponibility Off

我得到了这样一个域类:

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
    }
}
将其填充到控制器中时:

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,这是我问题中最奇怪的部分,第一次调用控制器时的第一个stacktrace apear:

| 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
第二个始终是最后一个堆栈跟踪:

| 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

添加FailOneError:true未更改堆栈跟踪。

制作:

if (!offer.save()) {
    log.error offer.errors
}
没有更改堆栈跟踪

谢谢你的阅读


Snite

我发现了什么是错误的,什么是阻塞

好的,编辑我的类,我发现这是一个关于抽象类的问题

记住我的课程:

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
    }
}
注释掉(上述类的成员变量)属性可以解决我的问题

这是我的属性类:

class Property extends Content {

    AssetManager assetManager
    Owner owner
    Mandat mandat
    AddressContent addressContent

    static hasMany = [
        buildings: Building,
        propertyMandats: PropertyMandat
    ]

    static constraints = {
        assetManager nullable: true
        mandat nullable: true
        owner nullable: true
    }
}
这是我的内容类:

abstract class Content {

    String name
    ExternalSystem externalSystem

    static constraints = {
        name nullable: true
        externalSystem nullable: true
    }

    @Override
    public String toString() { name }

}
Hibernate不生成任何“属性”表,但“内容”表类似于描述后的内容:

+---------------------+--------------+------+-----+---------+----------------+
| Field               | Type         | Null | Key | Default | Extra          |
+---------------------+--------------+------+-----+---------+----------------+
| id                  | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| version             | bigint(20)   | NO   |     | NULL    |                |
| external_system_id  | bigint(20)   | YES  | MUL | NULL    |                |
| name                | varchar(255) | YES  |     | NULL    |                |
| class               | varchar(255) | NO   |     | NULL    |                |
| sys_admin_client_id | bigint(20)   | YES  | MUL | NULL    |                |
| is_public_offer     | bit(1)       | YES  |     | NULL    |                |
| public_offer        | varchar(255) | YES  |     | NULL    |                |
| fund_id             | bigint(20)   | YES  | MUL | NULL    |                |
| address_content_id  | bigint(20)   | YES  | MUL | NULL    |                |
| asset_manager_id    | bigint(20)   | YES  | MUL | NULL    |                |
| mandat_id           | bigint(20)   | YES  | MUL | NULL    |                |
| owner_id            | bigint(20)   | YES  | MUL | NULL    |                |
| last_name           | varchar(255) | YES  |     | NULL    |                |
| mail                | varchar(255) | YES  |     | NULL    |                |
| phone_number1       | varchar(255) | YES  |     | NULL    |                |
| phone_number2       | varchar(255) | YES  |     | NULL    |                |
| agency_id           | bigint(20)   | YES  | MUL | NULL    |                |
| begin_date          | datetime     | YES  |     | NULL    |                |
| client_owner_id     | bigint(20)   | YES  | MUL | NULL    |                |
| end_date            | datetime     | YES  |     | NULL    |                |
| mandat_number       | varchar(255) | YES  |     | NULL    |                |
+---------------------+--------------+------+-----+---------+----------------+
我的内容类扩展了很多类

因此,我想问题在于没有创建“property”表

为什么会有这种行为?
我的内容抽象课有什么问题吗?

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

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


希望有用。

关于您的
内容表问题

“在数据库级别,Grails默认情况下使用每个层次结构的
映射,并使用名为
的鉴别器列,以便父类(内容)及其子类(BlogEntry、Book等)共享同一个表。”

Grails框架参考文档-GORM中的7.2.3继承


希望这能有所帮助。

我花了两天的时间从头抓起,直到我意识到,我有一个名为Property的变量。已更改为属性。非常感谢。