org.hibernate.HibernateException: Wrong column type Found: char, expected: varchar2(255)

Posted: October 13, 2009 in Hibernate

Problem:
org.hibernate.HibernateException: Wrong column type Found: char, expected: varchar2(255)

This exception was raised for the mapping:

@Column(name = "CNTRY_NM")
public String getCountry() {
return country;
}

Analysis:
This means to say that Hibernate has found char as the dataType of the column in the DATABASE and in your mapping you specified the data type as String.

    By default, the Hibernate converts java.lang.String to varchar2(255).

In other words, the data type of ‘CNTRY_NM’ column was defined as CHAR(50 Byte) in the database. Where as the data type of the corresponding attribute in the Entity class is java.lang.String. As there is a mismatch in the columns, the exception is thrown. When you specify schema validation by Hibernate (hibernate.hbm2ddl.auto = validate) this exception is thrown.

Solution:
@Column(name = “CNTRY_NM”, columnDefinition = “char”)
public String getCountry() {
return country;
}

About these ads
Comments
  1. Savannah says:

    Awesome blog!

    I thought about starting my own blog too but I’m just too lazy so, I guess Ill just have to keep checking yours out.
    LOL,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s