我正在尝试使用Grails的现有数据库。我的DataSource.groovy从这开始:

import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration
dataSource {
    configClass = GrailsAnnotationConfiguration.class
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = "12345"

}

我的班级注释如下:

@Entity
@Table(name = "regexpression", catalog = "tigger")
@SuppressWarnings("serial")
public class Regexpression implements Serializable {

    /**
     * Attribute regexpId.
     */
    private Integer regexpId;

    . . . 

    /**
     * <p> 
     * </p>
     * @return regexpId
     */
    @Basic
    @Id
    @GeneratedValue
    @Column(name = "regexp_id")
        public Integer getRegexpId() {
        return regexpId;
    }
        . . . 

当我运行生成的代码时,我收到以下错误:

org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error evaluating expression [regexpressionInstance.id] on line [40]: groovy.lang.MissingPropertyException: No such property: id for class: org.maflt.flashlit.pojo.Regexpression

所以看起来Grails忽略了regexp_id上的@Id注释。 那是核心吗?

我计划将数据库更改为使用id而不是regexp_id。但我也不应该。

有什么想法吗?

谢谢!

有帮助吗?

解决方案

嗯,您可能已经忘记了命名整数字段ID,然后只需将@Column注释指向表中regexp_id列的该属性。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top