-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: char mapping problem
PostPosted: Thu May 24, 2007 6:28 am 
Newbie

Joined: Thu May 24, 2007 5:27 am
Posts: 2
Hi, Im having trouble with char mapping to String.
I have a table called "mrconso" in my MySQL database and the following entity:

@Entity
@Table(name = "MRCONSO")
@NamedQuery(name = "mrconsoStr", query = "select i from Mrconso i where str like :terms")
public class Mrconso implements Serializable {

private Blob str;

private String cui;

@Id
@GeneratedValue
public Blob getStr() {
return str;
}

public void setStr(Blob str) {
this.str = str;
}

public String getCui() {
return cui;
}

public void setCui(String cui) {
this.cui = cui;
}

}

there is a problem with the "cui" field; in the database it is a char(8) but I want it as a String when I recover it from the entity. If the entity is defined as I wrote before, I get the following error:
HibernateException: Wrong column type: cui, expected: varchar(255)

I think the problem comes because it is a char(8) and not varchar(8) because I have other fields that are varchar and I dont get problems with that.

What should I do?

thanks in advance



Hibernate version:
3.1.3

Full stack trace of any exception that occurs:

--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: persistence.units:ear=WP7.ear,jar=WP7.jar,unitName=WP7
State: FAILED
Reason: javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: cui, expected: varchar(255)
I Depend On:
jboss.jca:service=DataSourceBinding,name=WP7Datasource
Depends On Me:
jboss.j2ee:ear=WP7.ear,jar=WP7.jar,name=SearchBean,service=EJB3


Name and version of the database you are using:
Mysql 5.0.37


Top
 Profile  
 
 Post subject: solution
PostPosted: Fri May 25, 2007 10:17 am 
Newbie

Joined: Thu May 24, 2007 5:27 am
Posts: 2
I solved it putting @Basic @Column(columnDefinition = "char") in front of the getter


@Basic
@Column(columnDefinition = "char")
public String getCui() {
return cui;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.