0

我想创建一个代表各种 JPA NamedQueries 的枚举。虽然每个查询可能有不同数量/类型的参数。因此,当我想引用查询/查询占位符时,我可以执行以下操作:

Entity.Queries.FIND_PERSON_BY_NAME_AND_ADDRESS.toString(); //gets the Query itself

Entity.Queries.Query1.FIND_PERSON_BY_NAME_AND_ADDRESS.PLACEHOLDER_NAME ; //gets the string of the placeholder "name"

Entity.Queries.Query1.FIND_PERSON_BY_NAME_AND_ADDRESS.PLACEHOLDER_ADDRESS;  //gets the String of the placeholder "address"

我想这样做,所以当我创建命名查询时,我可以执行以下操作

Query q = entitiManager.createNamedQuery(Entity.Queries.FIND_PERSON_BY_NAME_AND_ADDRESS.toString); 
q.setParameter(Entity.Queries.Query1.FIND_PERSON_BY_NAME_AND_ADDRESS.PLACEHOLDER_ADDRESS, address);

这对枚举是否可行,或者我应该只在私有静态类中使用最终常量或其他什么?

4

0 回答 0