Hibernate5 - change all VARCHAR(255) to TEXT without mapping field by field?

772 views Asked by At

Is it possible for Hibernate5 to map all Strings to TEXT; without annotating or mapping each field individually?

UPDATE

I've been doing some research on this and getting very close, but still no obvious path to a solution.

Clue #1enter image description here from https://docs.jboss.org/hibernate/orm/5.1/userguide/html_single/Hibernate_User_Guide.html

Tha link goes into https://docs.jboss.org/hibernate/orm/5.1/userguide/html_single/Hibernate_User_Guide.html#basic-custom-type, which is another rabbit-hole

1

There are 1 answers

0
Giang Phan On BEST ANSWER

With hibernate you can ignore Annotation on each field if the field name and the column is the same. For example: Database: USER_NAME -> Field name: user_name;

To map VARCHAR type to String, you can create a custom Dialect. For example, If you use MySQL, you can create a class extend MySQLDialect and create mapping data type.

public class CustomMySQLDialect extends MySQLDialect  {
    public MySQLDialectDataType() {
        registerHibernateType(Types.NVARCHAR, 255, "string");
        registerHibernateType(Types.BIGINT, "long");
    }
}