Modifying annotation attribute value at runtime in java

Posted by Lici on Stack Overflow See other posts from Stack Overflow or by Lici
Published on 2010-06-17T13:41:00Z Indexed on 2010/06/17 13:43 UTC
Read the original article Hit count: 249

Filed under:
|

Hi folks:

some methods in our model pojos have been annotated like this:

@Column(name="cli_clipping_id", updatable=false, columnDefinition = "varchar(" + ModelUtils.ID_LENGTH + ") COLLATE utf8_bin")

columnDefinition attribute is database vendor dependant, so when trying to drop schema in HSQLDB using Hibernate it fails:

[ERROR] 16 jun 12:58:42.480 PM main [org.hibernate.tool.hbm2ddl.SchemaExport]
Unexpected token: COLLATE in statement [create table cms.edi_editorial_obj (edi_uuid varchar(23) COLLATE

]

To fix this, i'm thinking on this solution (but don't want to spend time if it isn't possible) , at runtime, for each method column annotated:

  • Get @Column annotation
  • Create a copy of the column annotation, setting columnDefinition null using javaassist.
  • set column method annotation to the copy column annotation object overriding the old one (i don't know it this is possible)

Is it possible to "hack" these methods this way?

Any help would be much appreciated ...

© Stack Overflow or respective owner

Related posts about java

Related posts about hibernate