Hibernate JPA and PostgreSQL: change type from String to text (@Lob)

In existing table with data populated, changing the column type from string to text requires some migration.

For large data type, Postgres stores the data in a separate location and just references it by using an ID. This means that, until then, column data would be a string content and after the change, it would be just an ID referencing the real data.

So, if no changes are done on the database, Java will fail saying it read the string instead of an ID.

After doing some research, I found that other people encountered this problem too and, luckily, some have solved it. Here are the links:

https://stackoverflow.com/questions/14512771/how-do-i-migrate-postgresql-strings-to-a-text-type

https://github.com/divukman/miscellaneous_fork_tyag/blob/master/dataMigration.sql

https://github.com/tyagiakhilesh/miscellaneous/commit/834ecb753ccad58782a0545a713b8dd74cf09c8f