views:

116

answers:

1

I'm trying to use an existing database with Grails. My DataSource.groovy starts with this:

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

}

I have my class annotated as follows:

@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;
    }
        . . .

When I run the generated code I get the following error:

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

So it appears that Grails is ignoring the @Id annotation on regexp_id. Is that corect?

I plan to change the database to use id instead of regexp_id. But I shouldn't have too.

Any ideas?

Thanks!

A: 

Hmm, you might have gotten away with naming the Integer field id, then just putting the @Column annotation to point that property at the regexp_id column in the table.

Bill James
I bet you're right. I was hoping to test it, but it turns out I've gone too far down the road to go back at this point.Thanks!
Brad Rhoads