tags:

views:

55

answers:

2

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 ...

+1  A: 

If you are building with ANT, you could do a precompile step and use a regex to change the code in the files.

Romain Hippeau
I'm not using Ant and i'm wondering how to modify class files not code source
Lici
@Lici I was just trying to give you an alternate solution.
Romain Hippeau
I know .... (+1)
Lici
+1  A: 

I don't think the method you suggest is possible because:

  1. The annotation value which you get at runtime is actually a proxy class implementing the annotation interface. You can't set new values to its attributes.
  2. It is not possible to set new annotation values to the classes or methods at runtime.

However, you can move to a xml based configuration for Hibernate where you can modify the parameter from outside the code.

abhin4v