2

I have a Grails project that uses Hibernate XML with domain classes in the src/groovy folder. I am upgrading from 1.0.3 to 1.3.7. The Hibernate XML has custom column names for some properties and the domain classes use those properties. However, when I run the application it generates new columns for the properties as if they didn't have a column property:

XML for User:

    <class name="User" table="x_users">
        <cache usage="read-write"/>
        <comment>User</comment>
...
<property name="emailAddress" column="emailAddress"/>
...
</class>

</hibernate-mapping>

Domain for User (in src/groovy):

package com.x.domain

class User {
...
  String emailAddress
...
}

This results in the column email_address being created upon running the applications. Any ideas?

UPDATE:

Even if I add mappings to the domain class, it STILL creates the new column:

class User {
    static mapping = {
        emailAddress column:'emailAddress'
        }
}

3 Answers 3

1

You can cusomize the column name in the domain class itself, e.g.

class User {
  String emailAddress

  static mapping = {
    emailAddress column: "emailAddress"        
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

should I really have to do this in both places though?
Even that isn't working - it is totally ignoring the mappings in the src/groovy folder.
0

It looks like you cannot specify a capital letter in Hibernate 3 XML for Grails. When I change the mapping to:

 <class name="User" table="x_users">
        <cache usage="read-write"/>
        <comment>User</comment>
...
<property name="emailAddress" column="test"/>
...
</class>

it works correctly. When I change it to anything lowercase it works correctly, but introducing the capital causes it to go with the default value.

Comments

0

@skaz: I think you had better put your domain class into grails-app/domain folder. The folder src/groovy is for non-persistent domain class (that will not get saved in database), so that it won't get grails mapping way. That's also the reason why Don's method didn't work.

In my experience, the porting will not be too hard. After that you can drop the hibernate config and only use grails ORM mapping (as Don point out).

3 Comments

Long - You can't put them in the grails-app/domain folder when you are using Hibernate XML. Also, it isn't related to why Don's method didn't work. I am going to post an answer as to why.
@skaz: sorry for the not-clear explanation, but my propose is that dropping the Hibernate XML and taking the full support of Grails. When you config with Hibernate XML, it's the same with other Java Framework (Spring, Struts...) and you won't get much advantage from Grails' support.
@skaz: As I know, Don's method works without xml config if the class is in grails-app/domain folder. But in src/groovy folder, it will not work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.