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

Asked

Viewed 412 times

4

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

For that I added these annotations in the field:

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

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

  • But this change you expect to happen after the creation of the database already with the column created as varchar(255) formerly?

2 answers

2

How about trying to use that?

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

By the way, you didn’t 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 put 10000 quietly. In Oracle 8 to 11g, it seems that the limit is 4000.

An alternative:

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

Reference: https://stackoverflow.com/q/15135905/540552

  • Thanks for the tip Victor. Hugs!

2


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

Keep in mind that the intention of these options is for development environment, the ideal in production is to change the database by its manager or by some update process.

  • Thanks for the clarification. I will do this. By the way the Bank is Postgresql.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.