Modifying annotation attribute value at runtime in java

后端 未结 3 1774
失恋的感觉
失恋的感觉 2021-01-14 02:24

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

@Column(name=\"cli_clipping_id\", updatable=false, columnDefinition = \"varchar(\" + ModelUtil         


        
相关标签:
3条回答
  • 2021-01-14 03:10

    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.

    0 讨论(0)
  • 2021-01-14 03:11

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

    0 讨论(0)
  • 2021-01-14 03:17

    Though, this is in fact an old thread the Answer two above is incorrect for point 2: actually class anotations can be changed while runtime.

    I am still curious how to get it done for methods.

    0 讨论(0)
提交回复
热议问题