Reputation: 6036
I have 100+ JPA classes in a project. Hibernate creates a database schema for all of them. String fields it makes of length 255.
Is there any way to configure Hibernate through application.properties file, for example, so that it creates String fields of 4000 length?
Upvotes: 1
Views: 7756
Reputation: 19
Size annotation could help:
@Size(max = 4000)
private String name;
See also this link.
Upvotes: 1
Reputation: 6036
I have found the solution in other area. Instead of forcing Hibernate create max length String fields I have converted the length of all created String fields to 4000.
I have created a database by default using Hibernate with String fields of 255 length. Then I have converted all String fields to 4000 length by doing the following steps.
I use PostgreSQL, so this solution is for it. For others it might need some changes.
select 'ALTER TABLE '||table_schema||'.'||table_name||' ALTER COLUMN '||column_name||' SET DATA TYPE character varying(4000);' from information_schema.columns where table_schema='public' and data_type='character varying' and character_maximum_length=255
to create a number of scripts that change the length of String fields from 255 to 4000.
Pay attention that I might need to change table_schema from public, that is in my case, to your one.
As a resuult all String fields in database with 255 length will change their length to 4000.
Upvotes: 0
Reputation: 999
Changing the default field length isn't possible. The 255
value is the default specified by JPA.
Upvotes: 1