静态元模型,jpa和字段名称作为字符串

Jer*_*nce 2 java hibernate jpa metamodel

我使用Hibernate Static Metamodel Generator Annotation Processor生成我的实体的元模型.因此,我可以通过使用这样的字段(编译检查安全)来正确地构建标准,而不是直接将字段名称指定为字符串:

MyClass_.myField
Run Code Online (Sandbox Code Playgroud)

我将旧代码迁移到这个新系统,但有些函数将字符串作为参数而不是SingularAttribute(元模型类型).

我现在不想改变这些功能的签名.

我的问题:我可以使用元模型访问字段名称并将其转换为字符串吗?

我想做类似的事情,MyClass_.myField.toString()但它不会返回该字段的名称.

Jer*_*nce 5

这很容易,我立即找不到它......

只需致电:

MyClass_.myField.getName()
Run Code Online (Sandbox Code Playgroud)