6

I have the following (Grails) domain object:

class Country {

Integer id
char country_abbr
String country_name

static mapping = {
    version false
    id name: 'id'
    table 'country'
    id generator:'identity', column:'id'
}

static constraints = {
}}

The 'country_abbr' field within the 'country table' has type: character(2). However, whenever I am setting the domain object's data type (for 'country_abbr') to String, initialization is failing with the following exception

 org.hibernate.HibernateException: Wrong column type in mydb.country for column country_abbr. Found: bpchar, expected: varchar(255)

On the other hand, leaving this type as a Java char would only retrieve the first character. Any ideas how may I map to this type? Also, what is bpchar exactly?

Thanks

6
  • 1
    Just a note: you don't need to add the id attribute, this is made automatic by Grails. Also, the convention is to use camelcase in your attributes, Grails will handle the conversion to underscores for retrieving data. String countryName will be translated to country_name in querys. Commented Oct 10, 2013 at 16:53
  • It seems a problem of Hibernate mapping. Could you try char[] for countryAbbr? Commented Oct 10, 2013 at 16:59
  • @SérgioMichels It still fails with char[]; thanks for the other tips :) Commented Oct 10, 2013 at 17:03
  • 1
    Can you try this approach: cedar715.wordpress.com/2009/10/13/…? Add to your mapping: country_abbr columnDefinition: 'char' Commented Oct 10, 2013 at 20:09
  • 1
    With the Grails way you don't need the @Column annotation. Just use as I wrote. Commented Oct 11, 2013 at 14:10

1 Answer 1

3

Just to make this question answered. The solution is to change the country_abbr mapping:

country_abbr columnDefinition: 'char'

Reference here.

Sign up to request clarification or add additional context in comments.

Comments

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.