1

QueryDSL creates for us some nice metamodel Q-classes, where the fields of those Q-classes are, whenever possible, paths of a specific type. For example, if you have an Integer field for age in your User class, the field will have a type of NumberPath in the QUser class.

Suppose I'm using QueryDSL to build up a query like

user.from(user).where(user.age.eq(30))

I'd like to be able to get user.age's path-type that exists in the QClass - that is, NumberPath.

Is this possible?

Michael Tontchev
  • 909
  • 8
  • 23
  • Could you sketch via pseudocode what you need? I am not sure if I understand you correctly. – Timo Westkämper Feb 27 '15 at 16:45
  • Sure. So say you have a class named User, which has an Integer age in it. The generated QClass has, instead of an Integer age field, a NumberPath age field. I'd like to be able to get the type of this age field and have it return NumberPath.class. – Michael Tontchev Mar 02 '15 at 14:38
  • 1
    By get you mean not accessing by field, but getting by name, something like `path.get("age")`? That's not supported. – Timo Westkämper Mar 02 '15 at 19:31

1 Answers1

0

Have you tried to simply call user.age.getClass()?

user.age instanceof NumerClass should also work.

If you have the bare name as String you could use reflection:

user.getClass().getDeclaredField("age").getType()

should return NumberPatch.class. A bit dirty, but should work.

Simon
  • 857
  • 5
  • 14