Problem changing the type of a column in the model using JPA annotation

4

I have a column in the database that is limited to receiving a varchar(255) , but I need to change that to a larger size.

For this I have added these annotations in the field:

@Column(nullable = true, columnDefinition = "TEXT")
@Length(max = 10000)

But this did not change the supported size of the column I want to change. How do I make this change using the JPA mapping?

    
asked by anonymous 22.04.2015 / 21:54

2 answers

2

As Victor Stafusa replied, just use the length property of the Column annotation, but if the database column is already created it will only change if the hibernate.hbm2ddl.auto option is update , create , create-drop .

Keep in mind that the intent of these options is for development environment, the ideal in production is to change the database through the manager or some upgrade process.

    
23.04.2015 / 00:59
2

How about trying to use this?

@Column(nullable = true, columnDefinition = "TEXT", length = 10000)

Incidentally, you did not say which database you used, but whatever, this length has to be within this limit. If you are using SQL Server, DB / 2 or MySQL, for example, you can place 10000 quietly. In Oracle 8 up to 11g, it looks like the limit is 4000.

Another alternative:

@Lob
@Column(nullable = true, columnDefinition = "TEXT")

Reference: link

    
23.04.2015 / 00:11