views:

2910

answers:

1

I am having trouble setting the type of a String, it goes like

public void setTextDesc(String textDesc) {
 this.textDesc = textDesc;
}

@Column(name="DESC")
@Lob
public String getTextDesc() {
 return textDesc;
}

and it didn't work, I checked the mysql schema and it remains varchar(255), I also tried,

@Column(name="DESC", length="9000")

or

@Column(name="DESC")
@Type(type="text")

I am trying to make the type to be TEXT, any idea would be well appreciated!

+8  A: 

You said "I checked the mysql schema and it remains varchar(255)" - did you expect Hibernate to automatically alter your database? It won't. Even if you have hibernate.hbm2ddl.auto set, I don't believe Hibernate would alter the existing column definition.

If you were to generate new database creation script, @Lob should generate "TEXT" type column if you don't specify length explicitly (or if you do and it's less that 65536). You can always force that by explicitly declaring type in @Column annotation, though keep in mind that's not portable between databases:

@Column(name="DESC", columnDefinition="TEXT")
ChssPly76
right, I dropped the database everytime I change the annotations, with hbm2ddl.auto on, so I expect that it would change when I check again (sorry for the ambiguity). Somehow, columnDefinition didn't work for me neither. Am I missing something else? thanks for the input, btw.
Specifying `columnDefinition` is as explicit as you can get - there must be something else going on. Are you sure your compiled class is getting picked up by Hibernate correctly? Is it extending / being extended by some other class? Can't think of anything else that might cause this off hand, but if you can post your entire source for this class, your Hibernate configuration and describe how you're running this, I'll certainly see if anything jumps at me. Also can you try adding a bogus property to this class and generating schema as SQL file to see if it appears there (sanity check)?
ChssPly76
I finally got it to work by putting @Indexed on the top of the class, but I can't reason to myself why that is....
Thank you so much by the way!
You're very welcome, but you've got me very curious now :-) What is `@Indexed`? I'm pretty sure that's not a Hibernate or JPA annotation. If you meant `@Index`, then I truly fail to see how that would change anything with regard to above issue... If you figure out what the problem was I'd appreciate if you post it as an answer here - I promise to upvote it :-)
ChssPly76
I am using @Indexed and @Analyzer, they are both from hibernate search. I am still investigating the issue. My belief tells me that since I am extending a third party plug-in library class for hibernate (gilead - LightEntity), and since Hibernate Annotation detects the raw java type to determine the db's col-def, I think somehow gilead prevents Hibernate from type casting unless it's implemented with search, where the search force it to Type cast.