English 中文(简体)
Grails将主要钥匙转向强硬型
原标题:Changing primary key id to String type in Grails

My Grails 2.0 app has a User domain object defined:

class User {

static mapping = {
    table "dt_user"
    columns {
      id column: user_id , generator: assigned , type: string 
    }
}

当我试图拯救我的诱杀装置档案中的新用户时,我这样做:

def user = new User(id: "smith").save(failOnError:true)

我有以下错误:

| Error 2012-01-13 10:09:42,659 [main] ERROR property.BasicPropertyAccessor  - IllegalArgumentException in class: User, setter method of property: id
| Error 2012-01-13 10:09:42,660 [main] ERROR property.BasicPropertyAccessor  - expected type: java.lang.Long, actual value: java.lang.String

我还试图将用户类别改为:

class User {
    static mapping = {
        table "dt_user"
        columns {
            id column: user_id , generator: assigned , type: string , name: id 
        }
    }

    String id 
}

造成上述错误的错误不复存在。 然而,我发现,这导致婴儿自动产生,完全无视<条码>遗传器:指定条款。

What am I doing wrong here?

最佳回答

在<代码>columns栏栏目中加以总结,就是主角。 这一点在某个时候(在我之前)可能是必要的,但只要我使用过铁路,而且现在显然已经破碎,这就是一种选择。 但你只能直接宣布一栏地图:

class User {

   String id

   static mapping = {
      table "dt_user"
      id column:  user_id , generator:  assigned 
   }
}

只要外地被宣布为“长处”,并编为“条码” 它将发挥作用;没有必要告诉管理总局,它可以说明这一点。

问题回答

暂无回答




相关问题
grails + gwt request handling via controllers

I am new to gwt. I am trying to integrate gwt+grails.Can anybody provide me a good example for handling the request using grails controllers and not a custom servlet.I will be really thankful if ...

Error loading the grails gwt module xml

I ve installed the plugin from this article by Peter http://www.cacoethes.co.uk/blog/groovyandgrails/the-command-pattern-w.... While compile time its not able to find the module file which is present ...

Sorting Objects Based on Custom Domain Class Methods

I have a domain class, in which I ve defined some methods which give the object a score based on different algorithms (eg. popularity). I now want to retrieve a list of these objects sorted by one of ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

热门标签