Home Alter table from jpa annotations in Java
Reply: 1

Alter table from jpa annotations in Java

I. Ad
I. Ad Published in 2018-01-11 16:25:17Z

I have a definition for a column like that:

private String my_column;

And by default in Postgres database type for this field is character varying(255).

Now, I want to change the data type for this column.

How I can do this without entry in database and alter table?

I tried this:

private String my_column;


@Column(columnDefinition = "TEXT")
private String my_column;

But, without results.

Rofgar Reply to 2018-01-11 16:29:42Z

The thing is, that JPA does not handle Schema changes. JPA maps your existing DB to Java Classes, it does not manage the database it self.

As for schema changes managment. A common practice is to have a schema migration tool to handle that, for example Flyway and Liquibase are a popular solutions.

There you can write a SQL script, to change the DB column type to "text" and it will apply those changes when you run the DB migration process.

Or you can always just access your DB and modify it manually.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.32001 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO