34

What is the correct mapping type from MySQL data type text to Java using Hibernate?

@Column(name = "STACKTRACE", length = Integer.MAX_VALUE)
public String getStacktrace() {
    return this.stacktrace;
}
naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
Alex
  • 4,033
  • 9
  • 37
  • 52
  • 3
    Integer.MAX_VALUE? Really? For every stack trace? I'd recommend something more reasonable that's CLOB-sized. – duffymo Jul 05 '10 at 13:33

4 Answers4

71

Try this:

@Column(name = "STACKTRACE")
@Type(type="text")
Maurice Perry
  • 32,610
  • 9
  • 70
  • 97
  • Dear Maurice, I tried the above but I am getting error. your help will be very appreciable. http://stackoverflow.com/questions/25094410/hibernate-abstractmethoderror-setcharacterstreamiljava-io-readerjv?noredirect=1#comment39048566_25094410 – Ashish Agarwal Aug 02 '14 at 12:50
  • Why not to use ``@Lob`` (although it should generate ``LONGTEXT``) type? – heroin Nov 22 '15 at 16:20
  • `@Type(type="text")` generates `longtext` column for me. How to generate `text` column from Hibernate mapping? – naXa stands with Ukraine Dec 26 '18 at 18:37
20

I think this solves the problem

@Column(length = 65535,columnDefinition="Text")
Miks
  • 201
  • 2
  • 3
8

The reverse engineering Hibernate Tools, makes from MySql Type text:

@Column(name = "COLUMNNAME", length = 65535)
Alex
  • 4,033
  • 9
  • 37
  • 52
1

To fix this issue, I had to annotate like below:

@Column(name="LONG_DESCRIPTION" , length = 65535, columnDefinition="TEXT")
@Type(type="text")'
Rakesh Burbure
  • 1,045
  • 12
  • 27