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!
@Type annotation is for hibernate i.e. to tell what type of data do you want to store in database. Let's take a simple example: @Type(type="yes_no") private boolean isActive; Here return type is boolean but the value which gets stored in the database will be in Y or N format instead of true / false .
The @Column annotation is defined as a part of the Java Persistence API specification. It's used mainly in the DDL schema metadata generation. This means that if we let Hibernate generate the database schema automatically, it applies the not null constraint to the particular database column.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With