0

I want to create a text field in a database with varchar(700) (I want 700 characters max). I tried to define it like this:

@Entity
@Table(name = "t_foo)
public class Foo {

@Column(unique = true, nullable = false)
@Id
private String idNational;

@Column(length=700)
private String comment;

...

The table generate has the following properties:

idNational varchar(255) NOT NULL

comment longtext NULL

I would really like the comment to be varchar(700). Is there a reason it makes it a longtext? Is there a way I can make it varchar? Maybe this is an easy question, but I haven't found the solution! Do I have to create the tables with DDL instead?

Thank you!

beanf
  • 37
  • 1
  • 7

2 Answers2

1

You don't say which database/version you're using but it sounds like a version of MySQL with a maximum length of 255 for varchar. The latest version supports larger varchars.

Since you're specifying a value > 255, it's using longtext instead.

MySQL 5.0.3 and later support varchars with length to 65,535 - earlier versions only 255.

MattR
  • 6,908
  • 2
  • 21
  • 30
  • You are right, I will remember to put my versions in next time! I am using 5.1.43 - so I created the tables by DDL, and they are 700 characters now ... – beanf Sep 10 '12 at 12:28
-1

It's problem with JPA provider configuration. Better solution is cretion of tables with DDL.

tomi
  • 706
  • 1
  • 6
  • 21