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;
}
1
  • 3
    Integer.MAX_VALUE? Really? For every stack trace? I'd recommend something more reasonable that's CLOB-sized. Commented Jul 5, 2010 at 13:33

4 Answers 4

72

Try this:

@Column(name = "STACKTRACE")
@Type(type="text")
Sign up to request clarification or add additional context in comments.

3 Comments

Dear Maurice, I tried the above but I am getting error. your help will be very appreciable. stackoverflow.com/questions/25094410/…
Why not to use @Lob (although it should generate LONGTEXT) type?
@Type(type="text") generates longtext column for me. How to generate text column from Hibernate mapping?
20

I think this solves the problem

@Column(length = 65535,columnDefinition="Text")

Comments

8

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

@Column(name = "COLUMNNAME", length = 65535)

2 Comments

Indeed. If you look at the MySqlDialect, you'll see that it uses the length to derive the type.
I think thats the better solution if you use JPA.
1

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

@Column(name="LONG_DESCRIPTION" , length = 65535, columnDefinition="TEXT")
@Type(type="text")'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.