3

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

Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
Alex R
  • 11,364
  • 15
  • 100
  • 180

1 Answers1

1

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");
    }
}
Giang Phan
  • 534
  • 7
  • 15