How to silently truncate strings while storing them when they are longer than the column length definition?

前端 未结 12 1411
梦谈多话
梦谈多话 2020-12-24 06:17

I have a web app, using EclipseLink and MySQL for storing data. Some of these data are strings, ie varchars in the DB. In the code of entities, the strings have attributes

12条回答
  •  难免孤独
    2020-12-24 06:32

    Maybe AOP will help:

    Intercept all set method in you JavaBean/POJO, and then get the filed to be set. Check if the field is annotate with @Column and field type is String. Then truncate the field if it's too long than length.

提交回复
热议问题