Text Field using Hibernate Annotation

Viewed 83780

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!

2 Answers

There is a way to set the default mapping for "String" type to be set to "text" type in the database.

Save the following file in the package where you have your entities. Please change the package name as well.

This will set all "String" type fields to "text" type in the db for the package specified.

package-info.java

@TypeDefs({
      @TypeDef(name="string",defaultForType=java.lang.String.class,typeClass=org.hibernate.type.TextType.class)
})

package com.package.app;

import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
Related